1
Fork 0
mirror of https://github.com/Steffo99/unimore-bda-3.git synced 2024-11-23 16:34:21 +00:00
bda-3-steffo/unimore_bda_3/loaders/gtrends.py

22 lines
635 B
Python
Raw Permalink Normal View History

2022-11-25 08:23:40 +00:00
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