Please check and see what I'm doing wrong. It keeps saying I need to define things that I thought were defined?

This commit is contained in:
Heather
2025-11-11 16:02:59 -05:00
parent a3ee361132
commit 69e076978f
2 changed files with 40 additions and 28 deletions

View File

@@ -96,7 +96,7 @@
"\n", "\n",
"# Load the dataset\n", "# Load the dataset\n",
"def pandas(pd):\n", "def pandas(pd):\n",
" file_path = pd.read_csv(\"Fast_Food_Dataset/nutrition.csv\") \n", " df = pd.read_csv('Fast_Food_Dataset/nutrition.csv')\n",
"\n", "\n",
" \n", " \n",
"\n", "\n",
@@ -106,14 +106,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 6,
"id": "heated-blade", "id": "heated-blade",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"#check first 15 rows\n", "#check first 15 rows\n",
"def data (read_csv):\n", "def data (read_csv):\n",
" data.head(15)" " data.head(15)\n",
"\n",
"\n",
"\n"
] ]
}, },
{ {
@@ -195,14 +198,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 8,
"id": "negative-highlight", "id": "negative-highlight",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"#######################################################################\n", "#######################################################################\n",
"def file_path():\n", "\n",
" file_path = pd.read_csv(\"Fast_Food_Dataset/nutrition.csv\") \n", "# Calculate calories from fat (assuming fat column is in grams)\n",
"# Formula: fat_grams * 9 calories per gram\n",
"def first_15():\n",
" first_15['fat_calories']= first_15['fat'] * 9\n",
"\n",
"### \n", "### \n",
"### Your data analysis may include a statistic and/or a data visualization\n", "### Your data analysis may include a statistic and/or a data visualization\n",
"#######################################################################" "#######################################################################"
@@ -210,24 +217,23 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 16,
"id": "victorian-burning", "id": "victorian-burning",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"ename": "NameError", "ename": "SyntaxError",
"evalue": "name 'pd' is not defined", "evalue": "invalid syntax (2142274504.py, line 2)",
"output_type": "error", "output_type": "error",
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;36m Cell \u001b[0;32mIn[16], line 2\u001b[0;36m\u001b[0m\n\u001b[0;31m def first_15('item', 'fat', 'fat_calories', 'calories'):\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[14], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m file_path \u001b[38;5;241m=\u001b[39m \u001b[43mpd\u001b[49m\u001b[38;5;241m.\u001b[39mread_csv(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFast_Food_Dataset/nutrition.csv\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"\u001b[0;31mNameError\u001b[0m: name 'pd' is not defined"
] ]
} }
], ],
"source": [ "source": [
"file_path = pd.read_csv(\"Fast_Food_Dataset/nutrition.csv\")" "# Display relevant columns\n",
"def first_15('item', 'fat', 'fat_calories', 'calories'):\n",
" return first_15"
] ]
}, },
{ {

View File

@@ -96,7 +96,7 @@
"\n", "\n",
"# Load the dataset\n", "# Load the dataset\n",
"def pandas(pd):\n", "def pandas(pd):\n",
" file_path = pd.read_csv(\"Fast_Food_Dataset/nutrition.csv\") \n", " df = pd.read_csv('Fast_Food_Dataset/nutrition.csv')\n",
"\n", "\n",
" \n", " \n",
"\n", "\n",
@@ -106,14 +106,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 6,
"id": "heated-blade", "id": "heated-blade",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"#check first 15 rows\n", "#check first 15 rows\n",
"def data (read_csv):\n", "def data (read_csv):\n",
" data.head(15)" " data.head(15)\n",
"\n",
"\n",
"\n"
] ]
}, },
{ {
@@ -195,14 +198,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 8,
"id": "negative-highlight", "id": "negative-highlight",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"#######################################################################\n", "#######################################################################\n",
"def file_path():\n", "\n",
" file_path = pd.read_csv(\"Fast_Food_Dataset/nutrition.csv\") \n", "# Calculate calories from fat (assuming fat column is in grams)\n",
"# Formula: fat_grams * 9 calories per gram\n",
"def first_15():\n",
" first_15['fat_calories']= first_15['fat'] * 9\n",
"\n",
"### \n", "### \n",
"### Your data analysis may include a statistic and/or a data visualization\n", "### Your data analysis may include a statistic and/or a data visualization\n",
"#######################################################################" "#######################################################################"
@@ -210,24 +217,23 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 16,
"id": "victorian-burning", "id": "victorian-burning",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"ename": "NameError", "ename": "SyntaxError",
"evalue": "name 'pd' is not defined", "evalue": "invalid syntax (2142274504.py, line 2)",
"output_type": "error", "output_type": "error",
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;36m Cell \u001b[0;32mIn[16], line 2\u001b[0;36m\u001b[0m\n\u001b[0;31m def first_15('item', 'fat', 'fat_calories', 'calories'):\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[14], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m file_path \u001b[38;5;241m=\u001b[39m \u001b[43mpd\u001b[49m\u001b[38;5;241m.\u001b[39mread_csv(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFast_Food_Dataset/nutrition.csv\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"\u001b[0;31mNameError\u001b[0m: name 'pd' is not defined"
] ]
} }
], ],
"source": [ "source": [
"file_path = pd.read_csv(\"Fast_Food_Dataset/nutrition.csv\")" "# Display relevant columns\n",
"def first_15('item', 'fat', 'fat_calories', 'calories'):\n",
" return first_15"
] ]
}, },
{ {