Spaces:
Sleeping
Sleeping
Update chart_generation.py
Browse files- chart_generation.py +5 -3
chart_generation.py
CHANGED
@@ -7,17 +7,19 @@ import numpy as np
|
|
7 |
def create_bar_plot(file, x_values, y_values):
|
8 |
df = pd.read_excel(file)
|
9 |
|
10 |
-
df['
|
11 |
|
12 |
if y_values == "":
|
13 |
counts = df['Simple_Source'].value_counts()
|
14 |
-
fig = plt.figure(figsize=(
|
15 |
counts.plot(kind='bar')
|
16 |
plt.title(f'Count of First Words in {x_values}')
|
17 |
plt.xlabel('First Word')
|
18 |
plt.ylabel('Count')
|
19 |
else:
|
20 |
-
|
|
|
|
|
21 |
fig, ax = plt.subplots(figsize=(16, 7))
|
22 |
|
23 |
count_df.plot(kind='bar', stacked=True, ax=ax)
|
|
|
7 |
def create_bar_plot(file, x_values, y_values):
|
8 |
df = pd.read_excel(file)
|
9 |
|
10 |
+
df['Simple_X'] = df[x_values].apply(lambda x: ' '.join(x.split(',')[0].split()[:2]) if type(x)==str else np.nan)
|
11 |
|
12 |
if y_values == "":
|
13 |
counts = df['Simple_Source'].value_counts()
|
14 |
+
fig = plt.figure(figsize=(16, 7))
|
15 |
counts.plot(kind='bar')
|
16 |
plt.title(f'Count of First Words in {x_values}')
|
17 |
plt.xlabel('First Word')
|
18 |
plt.ylabel('Count')
|
19 |
else:
|
20 |
+
df['Simple_Y'] = df[y_values].apply(lambda x: ' '.join(x.split(',')[0].split()[:2]) if type(x)==str else np.nan)
|
21 |
+
|
22 |
+
count_df = df.groupby(['Simple_Source', 'Simple_Y']).size().unstack(fill_value=0)
|
23 |
fig, ax = plt.subplots(figsize=(16, 7))
|
24 |
|
25 |
count_df.plot(kind='bar', stacked=True, ax=ax)
|