add analysis module
This commit is contained in:
1 parent
86d0d6582d
commit
fb97703cdd
11 files changed
+44
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,13 @@
|
||||
from analysis.io import load_sales
|
||||
from analysis.metrics import revenue_per_day
|
||||
from analysis.plotting import plot_daily_revenue
|
||||
|
||||
|
||||
def main() -> None:
|
||||
df = load_sales("resources/sales.csv")
|
||||
daily = revenue_per_day(df)
|
||||
plot_daily_revenue(daily)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,5 @@
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def load_sales(path: str) -> pd.DataFrame:
|
||||
return pd.read_csv(path, sep=",", encoding="utf-8")
|
||||
@@ -0,0 +1,6 @@
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def revenue_per_day(df: pd.DataFrame) -> pd.Series:
|
||||
revenue = df["quantity"] * df["unit_price"]
|
||||
return revenue.groupby(df["day"]).sum()
|
||||
@@ -0,0 +1,9 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def plot_daily_revenue(daily: pd.Series) -> None:
|
||||
daily.plot(kind="bar")
|
||||
plt.title("Daily Revenue")
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
Reference in new issue
Block a user