mirror of
https://github.com/StefBuwalda/whatsapp-wordcloud.git
synced 2025-10-29 18:59:58 +00:00
Update chatgpt.py
This commit is contained in:
24
chatgpt.py
24
chatgpt.py
@@ -11,25 +11,23 @@ data = word_frequency_dict
|
|||||||
TOP_N = 5
|
TOP_N = 5
|
||||||
|
|
||||||
# Collect top words globally or per author
|
# Collect top words globally or per author
|
||||||
combined = Counter()
|
combined = Counter() # type: ignore
|
||||||
for author in data:
|
for author in data:
|
||||||
combined.update(data[author])
|
combined.update(data[author]) # type: ignore
|
||||||
|
|
||||||
top_words = [word for word, _ in combined.most_common(TOP_N)]
|
top_words = [word for word, _ in combined.most_common(TOP_N)] # type: ignore
|
||||||
|
|
||||||
# Create DataFrame with only top words
|
# Create DataFrame with only top words
|
||||||
df = pd.DataFrame(data).fillna(0).astype(int)
|
df = pd.DataFrame(data).fillna(0).astype(int) # type: ignore
|
||||||
df = df.loc[df.index.intersection(top_words)]
|
df = df.loc[df.index.intersection(top_words)] # type: ignore
|
||||||
|
|
||||||
# Plot heatmap
|
|
||||||
import seaborn as sns
|
|
||||||
|
|
||||||
plt.figure(figsize=(8, 5))
|
plt.figure(figsize=(8, 5)) # type: ignore
|
||||||
sns.heatmap(
|
sns.heatmap( # type: ignore
|
||||||
df, annot=True, fmt="d", cmap="YlGnBu", cbar_kws={"format": "%.0f"}
|
df, annot=True, fmt="d", cmap="YlGnBu", cbar_kws={"format": "%.0f"}
|
||||||
)
|
)
|
||||||
plt.title(f"Top {TOP_N} Word Frequencies")
|
plt.title(f"Top {TOP_N} Word Frequencies") # type: ignore
|
||||||
plt.xlabel("Author")
|
plt.xlabel("Author") # type: ignore
|
||||||
plt.ylabel("Word")
|
plt.ylabel("Word") # type: ignore
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
plt.show()
|
plt.show() # type: ignore
|
||||||
|
|||||||
Reference in New Issue
Block a user