私の連絡先情報
郵便メール:
2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
pip install python-docx wordcloud matplotlib
import docx
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# 读取Word文件内容
def read_word_file(file_path):
doc = docx.Document(file_path)
full_text = []
for para in doc.paragraphs:
full_text.append(para.text)
return 'n'.join(full_text)
# 生成词云图
def generate_wordcloud(text):
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text)
# 显示词云图
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()
# 主函数
def main():
file_path = 'your_word_file.docx' # 替换为你的Word文件路径
text = read_word_file(file_path)
generate_wordcloud(text)
if __name__ == "__main__":
main()
知らせ:
中国語の文字化けがある場合は、次の方法で修正できます。
フォントの追加
wordcloud = WordCloud(width=800, height=400, background_color='white', font_path='simhei.ttf').generate(text)
変更後の効果:
詳しい説明
インストールライブラリ:
Word ファイルの内容を読み取ります。
ワードクラウド図を生成します。
予防
上記の手順により、Word ファイルを簡単に読み込んで、美しいワード クラウド図を生成することができます。