You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
4.1 KiB
128 lines
4.1 KiB
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Prezzi delle Zucche\n",
|
|
"\n",
|
|
"Carica le librerie necessarie e il dataset. Converti i dati in un dataframe contenente un sottoinsieme dei dati:\n",
|
|
"\n",
|
|
"- Considera solo le zucche con prezzo al bushel\n",
|
|
"- Converti la data in un mese\n",
|
|
"- Calcola il prezzo come media tra il prezzo massimo e minimo\n",
|
|
"- Converti il prezzo per riflettere il costo in base alla quantità per bushel\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"import numpy as np\n",
|
|
"from datetime import datetime\n",
|
|
"\n",
|
|
"pumpkins = pd.read_csv('../data/US-pumpkins.csv')\n",
|
|
"\n",
|
|
"pumpkins.head()\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"pumpkins = pumpkins[pumpkins['Package'].str.contains('bushel', case=True, regex=True)]\n",
|
|
"\n",
|
|
"columns_to_select = ['Package', 'Variety', 'City Name', 'Low Price', 'High Price', 'Date']\n",
|
|
"pumpkins = pumpkins.loc[:, columns_to_select]\n",
|
|
"\n",
|
|
"price = (pumpkins['Low Price'] + pumpkins['High Price']) / 2\n",
|
|
"\n",
|
|
"month = pd.DatetimeIndex(pumpkins['Date']).month\n",
|
|
"day_of_year = pd.to_datetime(pumpkins['Date']).apply(lambda dt: (dt-datetime(dt.year,1,1)).days)\n",
|
|
"\n",
|
|
"new_pumpkins = pd.DataFrame(\n",
|
|
" {'Month': month, \n",
|
|
" 'DayOfYear' : day_of_year, \n",
|
|
" 'Variety': pumpkins['Variety'], \n",
|
|
" 'City': pumpkins['City Name'], \n",
|
|
" 'Package': pumpkins['Package'], \n",
|
|
" 'Low Price': pumpkins['Low Price'],\n",
|
|
" 'High Price': pumpkins['High Price'], \n",
|
|
" 'Price': price})\n",
|
|
"\n",
|
|
"new_pumpkins.loc[new_pumpkins['Package'].str.contains('1 1/9'), 'Price'] = price/1.1\n",
|
|
"new_pumpkins.loc[new_pumpkins['Package'].str.contains('1/2'), 'Price'] = price*2\n",
|
|
"\n",
|
|
"new_pumpkins.head()\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Un semplice diagramma a dispersione ci ricorda che abbiamo dati mensili solo da agosto a dicembre. Probabilmente abbiamo bisogno di più dati per poter trarre conclusioni in modo lineare.\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import matplotlib.pyplot as plt\n",
|
|
"plt.scatter('Month','Price',data=new_pumpkins)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n",
|
|
"plt.scatter('DayOfYear','Price',data=new_pumpkins)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"\n---\n\n**Disclaimer (Avvertenza)**: \nQuesto documento è stato tradotto utilizzando il servizio di traduzione automatica [Co-op Translator](https://github.com/Azure/co-op-translator). Sebbene ci impegniamo per garantire l'accuratezza, si prega di tenere presente che le traduzioni automatiche possono contenere errori o imprecisioni. Il documento originale nella sua lingua nativa dovrebbe essere considerato la fonte autorevole. Per informazioni critiche, si raccomanda una traduzione professionale effettuata da un traduttore umano. Non siamo responsabili per eventuali malintesi o interpretazioni errate derivanti dall'uso di questa traduzione.\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.8.3-final"
|
|
},
|
|
"orig_nbformat": 2,
|
|
"coopTranslator": {
|
|
"original_hash": "b032d371c75279373507f003439a577e",
|
|
"translation_date": "2025-08-29T22:45:36+00:00",
|
|
"source_file": "2-Regression/3-Linear/notebook.ipynb",
|
|
"language_code": "it"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
} |