I am new to Python.
This is my code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.graph_objects as go
url = "https://storage.googleapis.com/courses_data/Assignment%20CSV/finance_liquor_sales.csv"
df = pd.read_csv(url)
print("Missing Data: \n", df.isna().sum())
df.dropna(inplace=True)
time_period = pd.date_range(start="2016-01-01", end="2019-12-31")
print(df[df["date"].isin(time_period)])
while df[df["date"]] in time_period:
popular_item = df.groupby("zip_code")["bottles_sold"].sum().sort_values(ascending=False)
print(popular_item)
popular_item = plt.scatter(df["zip_code"], df["bottles_sold"])
plt.title("Bottles Sold per region in 2016-2019")
plt.xlabel("Zip Code")
plt.ylabel("Bottles Sold")
plt.show()
I want to visualize the Bottles Sold per zip code in the time range 2016-2019 and tried to write a code
time_period = pd.date_range(start="2016-01-01", end="2019-12-31")
print(df[df["date"].isin(time_period)])
while df[df["date"]] in time_period:
to obtain a time range in my data, so the calculations be derived only from this specified time period.
You can modify your code like this: