-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be8133b
commit f5c7b69
Showing
26 changed files
with
359 additions
and
112 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Visualizzazione Scientifica/emotionCalculation/mostFrequentSurvey.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import matplotlib.pyplot as plt | ||
from wordcloud import WordCloud | ||
import pandas as pd | ||
import os | ||
from nltk.corpus import stopwords | ||
from nltk.tokenize import word_tokenize | ||
|
||
fields = ["Risposte"] | ||
df = pd.read_csv(os.path.join(os.path.dirname(__file__), | ||
"../dataset/sondaggio.csv"), usecols=fields) | ||
|
||
stop_words = set(stopwords.words('italian')) | ||
print(df["Risposte"]) | ||
|
||
df=df.dropna(axis=0,how='all') | ||
print(df) | ||
|
||
df["Risposte"] = df["Risposte"].apply(lambda x: " ".join( | ||
[word for word in word_tokenize(x) if word not in stop_words])) | ||
|
||
text = df["Risposte"] | ||
wordcloud = WordCloud( | ||
width=1920, | ||
height=1080, | ||
background_color='white', | ||
colormap = 'Reds_r', | ||
).generate(str(text)) | ||
|
||
plt.imshow(wordcloud) | ||
plt.axis("off") | ||
print(f"Saving survey wordcloud") | ||
plt.show() | ||
plt.savefig(os.path.join(os.path.dirname(__file__), | ||
f"../image/survayRandom.png")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-2.34 KB
...entifica/image/cameraRandomUn sincero in bocca al lupo a Roberto Casaleggio.png
Binary file not shown.
Binary file removed
BIN
-2.34 KB
Visualizzazione Scientifica/image/cameraRandomtweetsCarloCalenda.png
Binary file not shown.
Binary file removed
BIN
-2.34 KB
Visualizzazione Scientifica/image/cameraRandomtweetsEnricoLetta.png
Binary file not shown.
Binary file removed
BIN
-2.34 KB
Visualizzazione Scientifica/image/cameraRandomtweetsGiorgiaMeloni.png
Binary file not shown.
Binary file removed
BIN
-2.34 KB
Visualizzazione Scientifica/image/cameraRandomtweetsGiuseppeConteIT.png
Binary file not shown.
Binary file removed
BIN
-2.34 KB
Visualizzazione Scientifica/image/cameraRandomtweetsmatteorenzi.png
Binary file not shown.
Binary file removed
BIN
-2.34 KB
Visualizzazione Scientifica/image/cameraRandomtweetsmatteosalvinimi.png
Binary file not shown.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import pandas as pd | ||
import os | ||
|
||
# read csv | ||
groupedYear = {} | ||
for i in os.listdir(os.path.join(os.path.dirname(__file__), "../tweetPolitic")): | ||
print(i) | ||
df = pd.read_csv(os.path.join(os.path.dirname(__file__), | ||
"../tweetPolitic/" + i), sep=",", encoding="latin-1") | ||
|
||
df = pd.to_datetime(df["Datetime"]).dt.year | ||
|
||
df = df.value_counts().to_frame().reset_index() | ||
df.columns = ["Year", "Group"] | ||
df = df.groupby("Year").sum().reset_index() | ||
|
||
groupedYear[i.split(".")[0]] = df | ||
|
||
x = groupedYear["tweetsmatteosalvinimi"]["Year"].values | ||
print(x) | ||
|
||
for i in groupedYear["tweetsGiuseppeConteIT"]["Group"].values: | ||
print(i) | ||
|
||
ySalvini = groupedYear["tweetsmatteosalvinimi"]["Group"].values | ||
yRenzi = groupedYear["tweetsmatteorenzi"]["Group"].values | ||
yMeloni = groupedYear["tweetsGiorgiaMeloni"]["Group"].values | ||
yConte = groupedYear["tweetsGiuseppeConteIT"]["Group"].values | ||
yLetta = groupedYear["tweetsEnricoLetta"]["Group"].values | ||
yCalenda = groupedYear["tweetsCarloCalenda"]["Group"].values | ||
|
||
print(len(x)) | ||
print(len(ySalvini)) | ||
|
||
x_axis = np.arange(len(x)) | ||
|
||
plt.bar(x_axis - 0.3, ySalvini, 0.1, label="Salvini",) | ||
plt.bar(x_axis - 0.2, yCalenda, 0.1, label="Calenda") | ||
plt.bar(x_axis - 0.1, yRenzi, 0.1, label="Renzi") | ||
plt.bar(x_axis + 0, yMeloni, 0.1, label="Meloni") | ||
plt.bar(x_axis + 0.1, yConte, 0.1, label="Conte") | ||
plt.bar(x_axis + 0.2, yLetta, 0.1, label="Letta") | ||
|
||
plt.xticks(x_axis, x) | ||
plt.xlabel("Year") | ||
plt.ylabel("Number of Tweets") | ||
plt.title("Number of Tweets in each year") | ||
plt.legend() | ||
plt.show() | ||
|
||
|
||
# # Ygirls = [10,20,20,40] | ||
# # Zboys = [20,30,25,30] | ||
|
||
# # X_axis = np.arange(len(X)) | ||
|
||
# # plt.bar(X_axis - 0.2, Ygirls, 0.4, label = 'Girls') | ||
# # plt.bar(X_axis + 0.2, Zboys, 0.4, label = 'Boys') | ||
|
||
# # plt.xticks(X_axis, X) | ||
# # plt.xlabel("Groups") | ||
# # plt.ylabel("Number of Students") | ||
# # plt.title("Number of Students in each group") | ||
# # plt.legend() | ||
# # plt.show() |
Oops, something went wrong.