1
Fork 0
mirror of https://github.com/Steffo99/unimore-bda-3.git synced 2024-11-29 03:14:19 +00:00
bda-3-steffo/unimore_bda_3/loaders/gtrends.py
2023-07-02 09:08:57 +02:00

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