Commit d74a1dea by Patryk Czarnik

gotowe notatniki

parent 9308b618
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -2441,8 +2441,28 @@
]
},
{
"cell_type": "markdown",
"id": "65096c60-0917-4939-8aa0-95de69a4eafd",
"metadata": {},
"source": [
"We wczytanej tabeli mamy kolumny `cena` oraz `sztuk`, a dopiero ich iloczyn zawiera info o wartości transakcji.\n",
"\n",
"Do tabeli dodamy nową kolumnę `wartosc` , która będzie zawierać iloczyn."
]
},
{
"cell_type": "code",
"execution_count": 65,
"execution_count": 66,
"id": "a335695f-9e7f-4977-94be-484404276027",
"metadata": {},
"outputs": [],
"source": [
"sprzedaz['wartosc'] = sprzedaz.cena * sprzedaz.sztuk"
]
},
{
"cell_type": "code",
"execution_count": 67,
"id": "cfa4857f-99bb-4e89-a7e4-6c916efdcb11",
"metadata": {},
"outputs": [
......@@ -2474,6 +2494,7 @@
" <th>towar</th>\n",
" <th>cena</th>\n",
" <th>sztuk</th>\n",
" <th>wartosc</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
......@@ -2486,6 +2507,7 @@
" <td>biurko</td>\n",
" <td>149.99</td>\n",
" <td>4</td>\n",
" <td>599.96</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
......@@ -2496,6 +2518,7 @@
" <td>tablica</td>\n",
" <td>590.00</td>\n",
" <td>2</td>\n",
" <td>1180.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
......@@ -2506,6 +2529,7 @@
" <td>flamaster</td>\n",
" <td>0.99</td>\n",
" <td>51</td>\n",
" <td>50.49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
......@@ -2516,6 +2540,7 @@
" <td>gąbka</td>\n",
" <td>4.00</td>\n",
" <td>250</td>\n",
" <td>1000.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
......@@ -2526,6 +2551,7 @@
" <td>biurko</td>\n",
" <td>149.99</td>\n",
" <td>9</td>\n",
" <td>1349.91</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
......@@ -2536,6 +2562,7 @@
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9995</th>\n",
......@@ -2546,6 +2573,7 @@
" <td>dziurkacz</td>\n",
" <td>7.50</td>\n",
" <td>178</td>\n",
" <td>1335.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9996</th>\n",
......@@ -2556,6 +2584,7 @@
" <td>biurko</td>\n",
" <td>149.99</td>\n",
" <td>7</td>\n",
" <td>1049.93</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9997</th>\n",
......@@ -2566,6 +2595,7 @@
" <td>długopis</td>\n",
" <td>1.49</td>\n",
" <td>87</td>\n",
" <td>129.63</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9998</th>\n",
......@@ -2576,6 +2606,7 @@
" <td>biurko</td>\n",
" <td>149.99</td>\n",
" <td>10</td>\n",
" <td>1499.90</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9999</th>\n",
......@@ -2586,10 +2617,11 @@
" <td>gąbka</td>\n",
" <td>4.00</td>\n",
" <td>152</td>\n",
" <td>608.00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>10000 rows × 7 columns</p>\n",
"<p>10000 rows × 8 columns</p>\n",
"</div>"
],
"text/plain": [
......@@ -2606,23 +2638,23 @@
"9998 2015-05-01 Kraków Kozłowski meble biurko 149.99 \n",
"9999 2016-08-26 Kraków Kozłowski wyposażenie szkolne gąbka 4.00 \n",
"\n",
" sztuk \n",
"0 4 \n",
"1 2 \n",
"2 51 \n",
"3 250 \n",
"4 9 \n",
"... ... \n",
"9995 178 \n",
"9996 7 \n",
"9997 87 \n",
"9998 10 \n",
"9999 152 \n",
" sztuk wartosc \n",
"0 4 599.96 \n",
"1 2 1180.00 \n",
"2 51 50.49 \n",
"3 250 1000.00 \n",
"4 9 1349.91 \n",
"... ... ... \n",
"9995 178 1335.00 \n",
"9996 7 1049.93 \n",
"9997 87 129.63 \n",
"9998 10 1499.90 \n",
"9999 152 608.00 \n",
"\n",
"[10000 rows x 7 columns]"
"[10000 rows x 8 columns]"
]
},
"execution_count": 65,
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
......@@ -2632,9 +2664,168 @@
]
},
{
"cell_type": "markdown",
"id": "baf91a7e-573e-4335-91b2-041cd147df3f",
"metadata": {},
"source": [
"### Zadania:\n",
"1. Oblicz sumę wartości transakcji w całym pliku"
]
},
{
"cell_type": "code",
"execution_count": 69,
"id": "a8dc418a-d810-4cdc-8d01-4ba730318706",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8049567.3"
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sprzedaz.wartosc.sum()"
]
},
{
"cell_type": "markdown",
"id": "505a1ff6-1ce6-4d6a-b818-8ae3b31b00c1",
"metadata": {},
"source": [
"2. Oblicz sumę wartości transakcji w Katowicach"
]
},
{
"cell_type": "code",
"execution_count": 70,
"id": "b284f678-9e34-4cfe-a215-92527a366ed9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1456316.08"
]
},
"execution_count": 70,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sprzedaz[sprzedaz.miasto == 'Katowice'].wartosc.sum()"
]
},
{
"cell_type": "markdown",
"id": "dd64c472-980a-488d-b529-1103b78f92c4",
"metadata": {},
"source": [
"3. Oblicz liczbę transakcji, sumę wartości (i jeśli dasz radę sumaryczną liczbę sztuk) dotyczących towaru biurko w Katowicach"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "bf3ce0ea-4885-4e87-aaac-abc30aaf2b29",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"count 248.0\n",
"sum 391473.9\n",
"Name: wartosc, dtype: float64"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sprzedaz[(sprzedaz.towar == 'biurko') & (sprzedaz.miasto == 'Katowice')].wartosc.agg(['count', 'sum'])"
]
},
{
"cell_type": "markdown",
"id": "753d3b1d-64b7-4d46-8498-dffe519e2819",
"metadata": {},
"source": [
"Operację `agg` można też zastosować dla `DataFrame` i przekazać **słownik**, który mówi, jakiew funkcje mają być liczone dla jakich kolumn."
]
},
{
"cell_type": "code",
"execution_count": 75,
"id": "a77019c4-8e4d-4065-b99b-3495e5da0ca5",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>sztuk</th>\n",
" <th>wartosc</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>sum</th>\n",
" <td>2610.0</td>\n",
" <td>391473.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>NaN</td>\n",
" <td>248.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" sztuk wartosc\n",
"sum 2610.0 391473.9\n",
"count NaN 248.0"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sprzedaz[(sprzedaz.towar == 'biurko') & (sprzedaz.miasto == 'Katowice')].agg({'sztuk': ['sum'], 'wartosc': ['count', 'sum']})"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6554eb49-a75f-4a99-bee3-22077bc36162",
"id": "147e601a-49b2-4c20-96d3-e65b98acbca7",
"metadata": {},
"outputs": [],
"source": []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment