-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_sentiment_popolarita_genere.py
61 lines (37 loc) · 1.61 KB
/
plot_sentiment_popolarita_genere.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
df = pd.read_csv("dataset/Dataset.csv", error_bad_lines=False, sep=',')
def popolarita(x,df,title):
df['YouTube'].replace('', np.nan, inplace=True)
df['YouTube'].replace('errore', np.nan, inplace=True)
df['YouTube'].replace('Errore', np.nan, inplace=True)
df.dropna(subset=['YouTube'], inplace=True)
df['YouTube'] = df.YouTube.astype(float)
ax = sns.barplot(x='YouTube', y =x, data=df, palette="Blues_d")
ax.set(xlabel='', ylabel='', title=title)
ax.legend().set_title('')
return plt.show()
def grafico_freq(x, df, title):
df['YouTube'].replace('', np.nan, inplace=True)
df['YouTube'].replace('errore', np.nan, inplace=True)
df['YouTube'].replace('Errore', np.nan, inplace=True)
df.dropna(subset=['YouTube'], inplace=True)
df['YouTube'] = df.YouTube.astype(float)
fig, ax2 = plt.subplots(nrows=1)
freq = pd.crosstab(df[x], df["YouTube"])
relative = freq.div(freq.sum(axis=1), axis=0)
relative.plot(kind="bar", ax=ax2)
ax2.set_title("Relative frequency " + title)
ax2.legend(title="Popolarita", loc=6, bbox_to_anchor=(1.02, 0.5))
plt.subplots_adjust(right=0.8, hspace=0.6)
plt.xticks(rotation=0)
return plt.show()
def grafico1(df,genere):
ax = sns.countplot(x="Anno", data=df)
ax.set(xlabel='', ylabel='', title='{} popularity by Year'.format(genere))
ax.legend().set_title('')
return plt.show()
popolarita(x='Sentiment', df=df, title='Sentiment by Popularity')
popolarita(x='Genere',df=df, title='Popularity by Genre')