1
Fork 0
mirror of https://github.com/Steffo99/unimore-bda-3.git synced 2024-12-01 12:14:21 +00:00
bda-3-steffo/unimore_bda_3/loaders/steamdb.py

49 lines
1.3 KiB
Python
Raw Normal View History

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