mirror of
https://github.com/Steffo99/unimore-bda-3.git
synced 2024-11-22 16:04:21 +00:00
21 lines
635 B
Python
21 lines
635 B
Python
from unimore_bda_3.prelude import *
|
|
|
|
|
|
def load(fd: t.IO[str], query_name: str) -> pd.DataFrame:
|
|
"""
|
|
Import a Google Trends CSV file into a :class:`pandas.DataFrame`.
|
|
"""
|
|
|
|
dataframe = pd.read_csv(fd, sep=",", header=1)
|
|
|
|
dataframe.rename(inplace=True, columns={
|
|
"Mese": "Date",
|
|
f"{query_name}: (Tutto il mondo)": "Google Trends · Score",
|
|
})
|
|
|
|
dataframe["Date"] = pd.to_datetime(dataframe["Date"])
|
|
dataframe["Google Trends · Score"] = dataframe["Google Trends · Score"].map(lambda x: int(x) if x != "< 1" else 0) / 100
|
|
|
|
dataframe.set_index("Date", inplace=True)
|
|
|
|
return dataframe
|