1
Fork 0
mirror of https://github.com/Steffo99/unimore-bda-3.git synced 2024-11-22 07:54:21 +00:00
bda-3-steffo/unimore_bda_3/loaders/steamdb.py
2023-07-02 09:08:57 +02:00

48 lines
1.3 KiB
Python

from unimore_bda_3.prelude import *
def load_players(fd: t.IO[str]) -> pd.DataFrame:
"""
Import a SteamDB "Lifetime player count history" CSV file into a `pandas.DataFrame`.
"""
dataframe = pd.read_csv(fd, sep=",")
dataframe.rename(inplace=True, columns={
"DateTime": "Date",
"Players": "SteamDB · Peak concurrent players",
"Average Players": "SteamDB · Day average of concurrent players",
"Flags": "SteamDB · Player count flags",
})
dataframe["Date"] = pd.to_datetime(dataframe["Date"])
dataframe.set_index("Date", inplace=True)
dataframe = dataframe.groupby(dataframe.index.date).max()
dataframe.index = pd.to_datetime(dataframe.index)
return dataframe
def load_price(fd: t.IO[str]) -> pd.DataFrame:
"""
Import a SteamDB "Price history" CSV file into a `pandas.DataFrame`.
"""
dataframe = pd.read_csv(fd, sep=",")
dataframe.rename(inplace=True, columns={
"DateTime": "Date",
"Final price": "SteamDB · Steam",
"Flags": "SteamDB · Price flags",
})
dataframe["Date"] = pd.to_datetime(dataframe["Date"])
dataframe.set_index("Date", inplace=True)
dataframe = dataframe.groupby(dataframe.index.date).min()
dataframe.index = pd.to_datetime(dataframe.index)
return dataframe