# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: 'Python 3.7.10 64-bit (''myenv'': conda)'
#     name: python3
# ---

# # The Pumpkin Market 
# #### Question 
# Predict the price of a pumpkin for a sale during a given month 

import pandas as pd
pumpkins = pd.read_csv('../data/US-pumpkins.csv')
pumpkins.head()

# the last 5 rows of data
pumpkins.tail()

# check missing data in the current dataframe 
pumpkins.isnull().sum()

# the packaging does not has a consistent measurement 
# so we are adding filter to our dataset 
pumpkins = pumpkins[pumpkins['Package'].str.contains('bushel', case=True, regex=True)]
print(pumpkins)

# we might want to drop some data to make it easier to work with 
new_coloumns = ['Package' , 'Month' , 'Low Price' , 'High Price' , 'Date'] # these are the columns that we want to keep
pumpkins = pumpkins.drop([c for c in pumpkins.columns if c not in new_coloumns], axis=1)

price = (pumpkins['Low Price'] + pumpkins['High Price']) / 2 
month = pd.DatetimeIndex(pumpkins['Date']).month
print(month)

new_pumpkins = pd.DataFrame({'Month': month, 'Package': pumpkins['Package'], 'Low Price': pumpkins['Low Price'],'High Price': pumpkins['High Price'], 'Price': price})
new_pumpkins.head()
print(new_pumpkins)

#standardize the pricing per bushel 
new_pumpkins.loc[new_pumpkins['Package'].str.contains('1 1/9') , 'Price'] = price/ ( 1 + 1/9)
new_pumpkins.loc[new_pumpkins['Package'].str.contains('1/2') , 'Price'] = price/ ( 1/2)
print(new_pumpkins)

# create the visualization 
import matplotlib.pyplot as plt 

price = new_pumpkins.Price
month = new_pumpkins.Month
plt.scatter(price, month)
plt.show()

new_pumpkins.groupby(['Month'])['Price'].mean().plot(kind='bar')
plt.ylabel("Pumpkin Price")

StarcoderdataJupyterScriptsDedupFiltered