Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -105,7 +105,7 @@ def generate_bar_chart(df, num_clusters_to_display):
|
|
| 105 |
df_top_clusters = df[df['Cluster'].isin(top_clusters)]
|
| 106 |
|
| 107 |
cluster_top_words = df_top_clusters.groupby('Cluster')['texts'].apply(lambda x: ' '.join(x)).reset_index()
|
| 108 |
-
cluster_top_words['top_word'] = cluster_top_words['texts'].apply(lambda x: pd.Series(x.split()).value_counts().index[0])
|
| 109 |
cluster_sizes = df_top_clusters['Cluster'].value_counts().reset_index()
|
| 110 |
cluster_sizes.columns = ['Cluster', 'Count']
|
| 111 |
cluster_sizes = cluster_sizes.merge(cluster_top_words[['Cluster', 'top_word']], on='Cluster')
|
|
|
|
| 105 |
df_top_clusters = df[df['Cluster'].isin(top_clusters)]
|
| 106 |
|
| 107 |
cluster_top_words = df_top_clusters.groupby('Cluster')['texts'].apply(lambda x: ' '.join(x)).reset_index()
|
| 108 |
+
cluster_top_words['top_word'] = cluster_top_words['texts'].apply(lambda x: pd.Series(x.split()).value_counts().index[0] if len(x.split()) > 0 else '')
|
| 109 |
cluster_sizes = df_top_clusters['Cluster'].value_counts().reset_index()
|
| 110 |
cluster_sizes.columns = ['Cluster', 'Count']
|
| 111 |
cluster_sizes = cluster_sizes.merge(cluster_top_words[['Cluster', 'top_word']], on='Cluster')
|