{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "1424e0d5",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a4d5b34d",
"metadata": {},
"outputs": [],
"source": [
"rjecnik = {\n",
" 'stupac1':[ 1, 2, 3],\n",
" 'stupac2': [4, 5, 6],\n",
" 'stupac3': [7, 8, 9]\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "35c2e3b5",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" stupac1 | \n",
" stupac2 | \n",
" stupac3 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1 | \n",
" 4 | \n",
" 7 | \n",
"
\n",
" \n",
" 1 | \n",
" 2 | \n",
" 5 | \n",
" 8 | \n",
"
\n",
" \n",
" 2 | \n",
" 3 | \n",
" 6 | \n",
" 9 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" stupac1 stupac2 stupac3\n",
"0 1 4 7\n",
"1 2 5 8\n",
"2 3 6 9"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tablica_rjecnik = pd.DataFrame(rjecnik)\n",
"tablica_rjecnik"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "560ba847",
"metadata": {},
"outputs": [],
"source": [
"vozni_park = {\n",
" #[\"tip\" \"marka\" \"registracija\" \"godiste\"]\n",
" 1 : [\"Kamion\", \"Iveco\", \"OS 001 ZZ\", 2015, 45000.00], \n",
" 2 : [\"Kamion\", \"Iveco\", \"OS 002 ZZ\", 2015, 47000.00],\n",
" 3 : [\"Tegljač\", \"MAN\", \"RI 001 ZZ\", 2018, 78000.00],\n",
" 4 : [\"Tegljač\", \"MAN\", \"RI 002 ZZ\", 2020, 97000.00],\n",
" 5 : [\"Kombi\", \"Mercedes\", \"ST 001 ZZ\", 2013, 12000.00],\n",
" 6 : [\"Kombi\", \"Volkswagen\", \"ST 002 ZZ\", 2021, 35000.00],\n",
" 7 : [\"Dostavno \", \"Volkswagen\", \"ZG 001 ZZ\", 2010, 9000.00],\n",
" 8 : [\"Dostavno \", \"Volkswagen\", \"ZG 002 ZZ\", 2010, 9300.00]\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "9e501bf8",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 1 | \n",
" 2 | \n",
" 3 | \n",
" 4 | \n",
" 5 | \n",
" 6 | \n",
" 7 | \n",
" 8 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Kamion | \n",
" Kamion | \n",
" Tegljač | \n",
" Tegljač | \n",
" Kombi | \n",
" Kombi | \n",
" Dostavno | \n",
" Dostavno | \n",
"
\n",
" \n",
" 1 | \n",
" Iveco | \n",
" Iveco | \n",
" MAN | \n",
" MAN | \n",
" Mercedes | \n",
" Volkswagen | \n",
" Volkswagen | \n",
" Volkswagen | \n",
"
\n",
" \n",
" 2 | \n",
" OS 001 ZZ | \n",
" OS 002 ZZ | \n",
" RI 001 ZZ | \n",
" RI 002 ZZ | \n",
" ST 001 ZZ | \n",
" ST 002 ZZ | \n",
" ZG 001 ZZ | \n",
" ZG 002 ZZ | \n",
"
\n",
" \n",
" 3 | \n",
" 2015 | \n",
" 2015 | \n",
" 2018 | \n",
" 2020 | \n",
" 2013 | \n",
" 2021 | \n",
" 2010 | \n",
" 2010 | \n",
"
\n",
" \n",
" 4 | \n",
" 45000.0 | \n",
" 47000.0 | \n",
" 78000.0 | \n",
" 97000.0 | \n",
" 12000.0 | \n",
" 35000.0 | \n",
" 9000.0 | \n",
" 9300.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 1 2 3 4 5 6 \\\n",
"0 Kamion Kamion Tegljač Tegljač Kombi Kombi \n",
"1 Iveco Iveco MAN MAN Mercedes Volkswagen \n",
"2 OS 001 ZZ OS 002 ZZ RI 001 ZZ RI 002 ZZ ST 001 ZZ ST 002 ZZ \n",
"3 2015 2015 2018 2020 2013 2021 \n",
"4 45000.0 47000.0 78000.0 97000.0 12000.0 35000.0 \n",
"\n",
" 7 8 \n",
"0 Dostavno Dostavno \n",
"1 Volkswagen Volkswagen \n",
"2 ZG 001 ZZ ZG 002 ZZ \n",
"3 2010 2010 \n",
"4 9000.0 9300.0 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vozni_df = pd.DataFrame(vozni_park)\n",
"vozni_df"
]
},
{
"cell_type": "markdown",
"id": "b591664e",
"metadata": {},
"source": [
"## Pandas tip podatka: _Series_ (serija)"
]
},
{
"cell_type": "markdown",
"id": "839a220f",
"metadata": {},
"source": [
"okomita lista, stupac"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "9f99da8b",
"metadata": {},
"outputs": [],
"source": [
"lista = [8, 3, 4, 0, 1, 2, 7, 2]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "843f6d89",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[8, 3, 4, 0, 1, 2, 7, 2]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lista"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "b23360da",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 8\n",
"1 3\n",
"2 4\n",
"3 0\n",
"4 1\n",
"5 2\n",
"6 7\n",
"7 2\n",
"Name: Serija cijelih brojeva, dtype: int64"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija = pd.Series(lista, name='Serija cijelih brojeva')\n",
"serija"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "bb48cbf7",
"metadata": {},
"outputs": [],
"source": [
"lista_dec = [6.5, 3, 8, 9.2, 10]"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "2026ed1e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 6.5\n",
"1 3.0\n",
"2 8.0\n",
"3 9.2\n",
"4 10.0\n",
"Name: Serija decimalnih brojeva, dtype: float64"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija2 = pd.Series(lista_dec, name='Serija decimalnih brojeva')\n",
"serija2"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "589c7c11",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 d\n",
"1 e\n",
"2 w\n",
"3 y\n",
"4 k\n",
"Name: Serija stringova, dtype: object"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lista_str = ['d','e','w','y','k']\n",
"serija3 = pd.Series(lista_str, name='Serija stringova')\n",
"serija3"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "b11626c5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 d\n",
"1 e\n",
"2 w\n",
"3 y\n",
"4 1\n",
"Name: Serija stringova, dtype: object"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lista_str = ['d','e','w','y',1]\n",
"serija3 = pd.Series(lista_str, name='Serija stringova')\n",
"serija3"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "c7adfbd1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 1\n",
"1 3\n",
"2 5\n",
"3 7\n",
"4 k\n",
"Name: Serija stringova, dtype: object"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lista_str = [1,3,5,7,'k']\n",
"serija3 = pd.Series(lista_str, name='Serija stringova')\n",
"serija3"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "8b01ba31",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'stupac1': [1, 2, 3], 'stupac2': [4, 5, 6], 'stupac3': [7, 8, 9]}"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rjecnik"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "cd0bbfd3",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" stupac1 | \n",
" stupac2 | \n",
" stupac3 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1 | \n",
" 4 | \n",
" 7 | \n",
"
\n",
" \n",
" 1 | \n",
" 2 | \n",
" 5 | \n",
" 8 | \n",
"
\n",
" \n",
" 2 | \n",
" 3 | \n",
" 6 | \n",
" 9 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" stupac1 stupac2 stupac3\n",
"0 1 4 7\n",
"1 2 5 8\n",
"2 3 6 9"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tablica_rjecnik"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "349c9d3e",
"metadata": {},
"outputs": [],
"source": [
"serija4 = tablica_rjecnik['stupac2'] # serija iz stupca tablice/DataFrame-a"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "f149a4b1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 4\n",
"1 5\n",
"2 6\n",
"Name: stupac2, dtype: int64"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija4"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "4ccbb424",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"pandas.core.series.Series"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(serija4)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "ff76867c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija3[3] # dohvat po indeksu kao iz liste"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "09f783ab",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 2\n",
"b 6\n",
"c 7\n",
"d 9\n",
"Name: Indeksi slova, dtype: int64"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija5 = pd.Series([2,6,7,9], name='Indeksi slova', index=['a','b','c','d'])\n",
"serija5"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "29b28cd0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija5['b']"
]
},
{
"cell_type": "markdown",
"id": "8997a65c",
"metadata": {},
"source": [
"#### Primjena svojstva _slice_ na seriji"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "55aa62a2",
"metadata": {},
"outputs": [],
"source": [
"serija_10brojeva = pd.Series([4,6,1,8,5,3,0,9,2,5])\n",
"podskup = serija_10brojeva[2:8:2]"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "bff46788",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2 1\n",
"4 5\n",
"6 0\n",
"dtype: int64"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"podskup"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "eb3abaee",
"metadata": {},
"outputs": [
{
"ename": "KeyError",
"evalue": "0",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
"File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\core\\indexes\\range.py:345\u001b[0m, in \u001b[0;36mRangeIndex.get_loc\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m 344\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 345\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_range\u001b[38;5;241m.\u001b[39mindex(new_key)\n\u001b[0;32m 346\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n",
"\u001b[1;31mValueError\u001b[0m: 0 is not in range",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[32], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m podskup[\u001b[38;5;241m0\u001b[39m]\n",
"File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\core\\series.py:1007\u001b[0m, in \u001b[0;36mSeries.__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m 1004\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_values[key]\n\u001b[0;32m 1006\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m key_is_scalar:\n\u001b[1;32m-> 1007\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_get_value(key)\n\u001b[0;32m 1009\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_hashable(key):\n\u001b[0;32m 1010\u001b[0m \u001b[38;5;66;03m# Otherwise index.get_value will raise InvalidIndexError\u001b[39;00m\n\u001b[0;32m 1011\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m 1012\u001b[0m \u001b[38;5;66;03m# For labels that don't resolve as scalars like tuples and frozensets\u001b[39;00m\n",
"File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\core\\series.py:1116\u001b[0m, in \u001b[0;36mSeries._get_value\u001b[1;34m(self, label, takeable)\u001b[0m\n\u001b[0;32m 1113\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_values[label]\n\u001b[0;32m 1115\u001b[0m \u001b[38;5;66;03m# Similar to Index.get_value, but we do not fall back to positional\u001b[39;00m\n\u001b[1;32m-> 1116\u001b[0m loc \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mindex\u001b[38;5;241m.\u001b[39mget_loc(label)\n\u001b[0;32m 1118\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_integer(loc):\n\u001b[0;32m 1119\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_values[loc]\n",
"File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\core\\indexes\\range.py:347\u001b[0m, in \u001b[0;36mRangeIndex.get_loc\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m 345\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_range\u001b[38;5;241m.\u001b[39mindex(new_key)\n\u001b[0;32m 346\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n\u001b[1;32m--> 347\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01merr\u001b[39;00m\n\u001b[0;32m 348\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(key, Hashable):\n\u001b[0;32m 349\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key)\n",
"\u001b[1;31mKeyError\u001b[0m: 0"
]
}
],
"source": [
"podskup[0] # poremećeni indeksi, naslijeđeni iz original serije "
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "fb530a3f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"podskup[2]"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "663d0a26",
"metadata": {},
"outputs": [],
"source": [
"podskup.reset_index(inplace=True, drop=True)"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "5665e2c5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 1\n",
"1 5\n",
"2 0\n",
"dtype: int64"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"podskup"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "51aef0b7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"podskup[0]"
]
},
{
"cell_type": "markdown",
"id": "956cfd46",
"metadata": {},
"source": [
"#### Filtriranje iz serije"
]
},
{
"cell_type": "markdown",
"id": "6321e642",
"metadata": {},
"source": [
"Izdvajanje brojeva većih od 5 iz serije _serija_10brojeva_ "
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "50904ff1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1 6\n",
"3 8\n",
"7 9\n",
"dtype: int64"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_10brojeva[serija_10brojeva > 5]"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "ed8f2f0e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 6\n",
"1 8\n",
"2 9\n",
"dtype: int64"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"veci_od5 = serija_10brojeva[serija_10brojeva > 5]\n",
"veci_od5.reset_index(inplace=True, drop=True)\n",
"veci_od5"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "05a2ce17",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[5, 8, 3, 2, 9, 0, 4, 5, 8, 3, 2, 9, 0, 4, 5, 8, 3, 2, 9, 0, 4]"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lista_br = [5, 8, 3, 2, 9, 0, 4]\n",
"lista_br*3"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "98ffa219",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 18\n",
"1 24\n",
"2 27\n",
"dtype: int64"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"veci_od5*3"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "edd45fab",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 2.000000\n",
"1 2.666667\n",
"2 3.000000\n",
"dtype: float64"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"veci_od5 /3"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "6d143887",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 2.00\n",
"1 2.67\n",
"2 3.00\n",
"dtype: float64"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"round(veci_od5/3, 2)"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "2ef40cea",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{1, 2, 3, 4, 6, 7, 8}"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lista_ponavljanje = [1, 3, 6, 4, 1, 1, 7, 4, 7, 6, 8, 2, 4]\n",
"set(lista_ponavljanje)"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "cfbf517b",
"metadata": {},
"outputs": [],
"source": [
"serija_ponavljanje = pd.Series(lista_ponavljanje)"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "6eb1cd49",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 1\n",
"1 3\n",
"2 6\n",
"3 4\n",
"4 1\n",
"5 1\n",
"6 7\n",
"7 4\n",
"8 7\n",
"9 6\n",
"10 8\n",
"11 2\n",
"12 4\n",
"dtype: int64"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_ponavljanje"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "30afc5fc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 3, 6, 4, 7, 8, 2], dtype=int64)"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_ponavljanje.unique()"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "fac5424e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1 3\n",
"4 3\n",
"6 2\n",
"7 2\n",
"3 1\n",
"8 1\n",
"2 1\n",
"Name: count, dtype: int64"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_ponavljanje.value_counts()"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "2a400e87",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3 1\n",
"8 1\n",
"2 1\n",
"6 2\n",
"7 2\n",
"1 3\n",
"4 3\n",
"Name: count, dtype: int64"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_ponavljanje.value_counts().sort_values()"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "f60ae210",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 4\n",
"1 6\n",
"2 1\n",
"3 8\n",
"4 5\n",
"5 3\n",
"6 0\n",
"7 9\n",
"8 2\n",
"9 5\n",
"dtype: int64"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_10brojeva"
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "c978a333",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 True\n",
"1 False\n",
"2 False\n",
"3 False\n",
"4 False\n",
"5 False\n",
"6 True\n",
"7 True\n",
"8 True\n",
"9 False\n",
"dtype: bool"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_10brojeva.isin([2, 9, 0, 4])"
]
},
{
"cell_type": "code",
"execution_count": 58,
"id": "cb228c5a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 1\n",
"1 3\n",
"2 6\n",
"3 4\n",
"4 1\n",
"5 1\n",
"6 7\n",
"7 4\n",
"8 7\n",
"9 6\n",
"10 8\n",
"11 2\n",
"12 4\n",
"dtype: int64"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_ponavljanje"
]
},
{
"cell_type": "code",
"execution_count": 59,
"id": "f7574995",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 True\n",
"1 False\n",
"2 False\n",
"3 True\n",
"4 True\n",
"5 True\n",
"6 True\n",
"7 True\n",
"8 True\n",
"9 False\n",
"10 False\n",
"11 False\n",
"12 True\n",
"dtype: bool"
]
},
"execution_count": 59,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_ponavljanje.isin([1, 4, 7]) # na određenom mjestu (indexu) je ili nije bilo koji od njih (ne znamo koji)"
]
},
{
"cell_type": "code",
"execution_count": 60,
"id": "9e62a35a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 1\n",
"3 4\n",
"4 1\n",
"5 1\n",
"6 7\n",
"7 4\n",
"8 7\n",
"12 4\n",
"dtype: int64"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_ponavljanje[serija_ponavljanje.isin([1, 4, 7])] # koji je broj na kojem mjestu (indexu)"
]
},
{
"cell_type": "code",
"execution_count": 68,
"id": "9b62c0a0",
"metadata": {},
"outputs": [],
"source": [
"brojevi = [x for x in range(101)]\n",
"serija_brojevi = pd.Series(brojevi)\n"
]
},
{
"cell_type": "code",
"execution_count": 79,
"id": "4c7ddec2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 0\n",
"1 1\n",
"2 2\n",
"3 3\n",
"4 4\n",
"5 5\n",
"6 6\n",
"7 7\n",
"8 8\n",
"9 9\n",
"10 10\n",
"11 11\n",
"12 12\n",
"13 13\n",
"14 14\n",
"15 15\n",
"16 16\n",
"17 17\n",
"18 18\n",
"19 19\n",
"20 20\n",
"21 21\n",
"22 22\n",
"23 23\n",
"24 24\n",
"25 25\n",
"26 26\n",
"27 27\n",
"28 28\n",
"29 29\n",
"30 30\n",
"31 31\n",
"32 32\n",
"33 33\n",
"34 34\n",
"35 35\n",
"36 36\n",
"37 37\n",
"38 38\n",
"39 39\n",
"40 40\n",
"41 41\n",
"42 42\n",
"43 43\n",
"44 44\n",
"45 45\n",
"46 46\n",
"47 47\n",
"48 48\n",
"49 49\n",
"50 50\n",
"51 51\n",
"52 52\n",
"53 53\n",
"54 54\n",
"55 55\n",
"56 56\n",
"57 57\n",
"58 58\n",
"59 59\n",
"60 60\n",
"61 61\n",
"62 62\n",
"63 63\n",
"64 64\n",
"65 65\n",
"66 66\n",
"67 67\n",
"68 68\n",
"69 69\n",
"70 70\n",
"71 71\n",
"72 72\n",
"73 73\n",
"74 74\n",
"75 75\n",
"76 76\n",
"77 77\n",
"78 78\n",
"79 79\n",
"80 80\n",
"81 81\n",
"82 82\n",
"83 83\n",
"84 84\n",
"85 85\n",
"86 86\n",
"87 87\n",
"88 88\n",
"89 89\n",
"90 90\n",
"91 91\n",
"92 92\n",
"93 93\n",
"94 94\n",
"95 95\n",
"96 96\n",
"97 97\n",
"98 98\n",
"99 99\n",
"100 100\n",
"dtype: int64"
]
},
"execution_count": 79,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.set_option('display.max_rows', None)\n",
"serija_brojevi"
]
},
{
"cell_type": "markdown",
"id": "a4e946ee",
"metadata": {},
"source": [
"ZADATAK \n",
"Generirajte nasumičnih 100 brojeva rasponu od 1 do 100, te ih pohranite u Python listu. Od te liste kreirajte Pandas seriju te joj dajte nekakav naziv.\n",
"+ Provjerite, koliko ima brojeva koji se ponavljaju te koliko se puta svaki od njih ponavlja?\n",
" + Koji je broj najveći, a koji najmanji?\n",
" + Modificirajte podatke u seriji tako da se svedu na postotke (neka budu u rasponu od 0 do 1).\n",
" + Promijenite vrijednosti najvećeg broja tako da je identična vrijednosti najmanjeg broja. Provjerite koji je sada najveći broj."
]
},
{
"cell_type": "code",
"execution_count": 76,
"id": "7dbe5729",
"metadata": {},
"outputs": [],
"source": [
"pd.reset_option('display.max_rows')"
]
},
{
"cell_type": "code",
"execution_count": 77,
"id": "1ad1bb3e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 0\n",
"1 1\n",
"2 2\n",
"3 3\n",
"4 4\n",
" ... \n",
"96 96\n",
"97 97\n",
"98 98\n",
"99 99\n",
"100 100\n",
"Length: 101, dtype: int64"
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_brojevi"
]
},
{
"cell_type": "code",
"execution_count": 89,
"id": "25a65008",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 1\n",
"1 25\n",
"2 33\n",
"3 21\n",
"4 49\n",
"5 42\n",
"6 43\n",
"7 81\n",
"8 38\n",
"9 2\n",
"10 27\n",
"11 11\n",
"12 39\n",
"13 93\n",
"14 25\n",
"15 12\n",
"16 93\n",
"17 8\n",
"18 93\n",
"19 1\n",
"20 10\n",
"21 100\n",
"22 44\n",
"23 28\n",
"24 11\n",
"25 38\n",
"26 74\n",
"27 31\n",
"28 21\n",
"29 17\n",
"30 31\n",
"31 10\n",
"32 99\n",
"33 5\n",
"34 2\n",
"35 34\n",
"36 89\n",
"37 37\n",
"38 31\n",
"39 90\n",
"40 52\n",
"41 98\n",
"42 86\n",
"43 88\n",
"44 59\n",
"45 11\n",
"46 90\n",
"47 18\n",
"48 90\n",
"49 54\n",
"50 67\n",
"51 91\n",
"52 62\n",
"53 7\n",
"54 26\n",
"55 90\n",
"56 91\n",
"57 55\n",
"58 51\n",
"59 83\n",
"60 77\n",
"61 47\n",
"62 96\n",
"63 71\n",
"64 8\n",
"65 46\n",
"66 74\n",
"67 34\n",
"68 67\n",
"69 34\n",
"70 45\n",
"71 87\n",
"72 53\n",
"73 80\n",
"74 60\n",
"75 48\n",
"76 12\n",
"77 86\n",
"78 36\n",
"79 19\n",
"80 7\n",
"81 31\n",
"82 41\n",
"83 62\n",
"84 83\n",
"85 1\n",
"86 13\n",
"87 27\n",
"88 98\n",
"89 27\n",
"90 37\n",
"91 37\n",
"92 45\n",
"93 68\n",
"94 4\n",
"95 27\n",
"96 76\n",
"97 23\n",
"98 13\n",
"99 26\n",
"dtype: int64"
]
},
"execution_count": 89,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import random\n",
"brojevi_100 = []\n",
"for i in range(100):\n",
" x=random.randint(1,100)\n",
" brojevi_100.append(x)\n",
"serija_100 = pd.Series(brojevi_100)\n",
"serija_100"
]
},
{
"cell_type": "code",
"execution_count": 90,
"id": "53e08cd0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"31 4\n",
"27 4\n",
"90 4\n",
"34 3\n",
"37 3\n",
"93 3\n",
"11 3\n",
"1 3\n",
"91 2\n",
"74 2\n",
"62 2\n",
"7 2\n",
"25 2\n",
"26 2\n",
"98 2\n",
"83 2\n",
"45 2\n",
"13 2\n",
"67 2\n",
"86 2\n",
"21 2\n",
"10 2\n",
"8 2\n",
"38 2\n",
"12 2\n",
"2 2\n",
"28 1\n",
"80 1\n",
"96 1\n",
"71 1\n",
"46 1\n",
"87 1\n",
"53 1\n",
"48 1\n",
"60 1\n",
"77 1\n",
"36 1\n",
"19 1\n",
"41 1\n",
"33 1\n",
"68 1\n",
"4 1\n",
"76 1\n",
"47 1\n",
"55 1\n",
"49 1\n",
"51 1\n",
"17 1\n",
"99 1\n",
"5 1\n",
"100 1\n",
"89 1\n",
"52 1\n",
"39 1\n",
"88 1\n",
"59 1\n",
"18 1\n",
"54 1\n",
"81 1\n",
"43 1\n",
"42 1\n",
"44 1\n",
"23 1\n",
"Name: count, dtype: int64"
]
},
"execution_count": 90,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_100.value_counts()"
]
},
{
"cell_type": "code",
"execution_count": 91,
"id": "caaf33e9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 91,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_100.min()"
]
},
{
"cell_type": "code",
"execution_count": 92,
"id": "76bbc6df",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"100"
]
},
"execution_count": 92,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_100.max()"
]
},
{
"cell_type": "code",
"execution_count": 93,
"id": "04e448c3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"21 100\n",
"dtype: int64"
]
},
"execution_count": 93,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_100[serija_100.isin([serija_100.max()])]"
]
},
{
"cell_type": "code",
"execution_count": 94,
"id": "2bb2be5f",
"metadata": {},
"outputs": [],
"source": [
"index = list(serija_100).index(serija_100.max())"
]
},
{
"cell_type": "code",
"execution_count": 95,
"id": "c9571b6a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"21"
]
},
"execution_count": 95,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"index"
]
},
{
"cell_type": "code",
"execution_count": 88,
"id": "03c1dc2a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"99"
]
},
"execution_count": 88,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_100.max()"
]
},
{
"cell_type": "code",
"execution_count": 115,
"id": "7422f39d",
"metadata": {},
"outputs": [],
"source": [
"brojevi_100 = []\n",
"for i in range(100):\n",
" x=random.randint(1,20)\n",
" brojevi_100.append(x)"
]
},
{
"cell_type": "code",
"execution_count": 116,
"id": "e129bf76",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[6,\n",
" 8,\n",
" 14,\n",
" 8,\n",
" 10,\n",
" 17,\n",
" 13,\n",
" 15,\n",
" 10,\n",
" 17,\n",
" 16,\n",
" 1,\n",
" 3,\n",
" 11,\n",
" 15,\n",
" 9,\n",
" 13,\n",
" 15,\n",
" 2,\n",
" 17,\n",
" 15,\n",
" 7,\n",
" 17,\n",
" 11,\n",
" 14,\n",
" 3,\n",
" 15,\n",
" 3,\n",
" 20,\n",
" 7,\n",
" 13,\n",
" 12,\n",
" 5,\n",
" 5,\n",
" 8,\n",
" 9,\n",
" 9,\n",
" 7,\n",
" 1,\n",
" 13,\n",
" 9,\n",
" 16,\n",
" 19,\n",
" 17,\n",
" 7,\n",
" 2,\n",
" 19,\n",
" 9,\n",
" 17,\n",
" 2,\n",
" 6,\n",
" 10,\n",
" 7,\n",
" 12,\n",
" 20,\n",
" 10,\n",
" 2,\n",
" 17,\n",
" 11,\n",
" 3,\n",
" 5,\n",
" 9,\n",
" 16,\n",
" 13,\n",
" 16,\n",
" 4,\n",
" 17,\n",
" 2,\n",
" 16,\n",
" 1,\n",
" 11,\n",
" 6,\n",
" 9,\n",
" 12,\n",
" 4,\n",
" 8,\n",
" 2,\n",
" 6,\n",
" 16,\n",
" 19,\n",
" 2,\n",
" 9,\n",
" 11,\n",
" 11,\n",
" 10,\n",
" 10,\n",
" 4,\n",
" 10,\n",
" 20,\n",
" 6,\n",
" 10,\n",
" 2,\n",
" 2,\n",
" 14,\n",
" 12,\n",
" 9,\n",
" 19,\n",
" 2,\n",
" 15,\n",
" 13]"
]
},
"execution_count": 116,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"brojevi_100"
]
},
{
"cell_type": "code",
"execution_count": 120,
"id": "2b2d900c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[28, 54, 88]"
]
},
"execution_count": 120,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lista_max_indeksi=[]\n",
"for i,broj in enumerate(brojevi_100):\n",
" if broj == max(brojevi_100):\n",
" lista_max_indeksi.append(i)\n",
"lista_max_indeksi"
]
},
{
"cell_type": "code",
"execution_count": 122,
"id": "3be17737",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[21]"
]
},
"execution_count": 122,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list_serija_100 = [i for i, x in enumerate(serija_100) if x == serija_100.max()]\n",
"list_serija_100"
]
},
{
"cell_type": "markdown",
"id": "e58b3e37",
"metadata": {},
"source": [
"**ZADATAK** \n",
"Tekst za obradu:"
]
},
{
"cell_type": "markdown",
"id": "4632acd2",
"metadata": {},
"source": [
"__Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.__"
]
},
{
"cell_type": "markdown",
"id": "10a8c599",
"metadata": {},
"source": [
"Obradite gore navedeni tekst tako da od njega kreirate listu riječi koje imaju sva mala slova i nemaju znakove interpunkcije. Od te liste kreirajte Pandas seriju te joj dajte nekakav naziv."
]
},
{
"cell_type": "markdown",
"id": "23ed0c3b",
"metadata": {},
"source": [
" + Provjerite, koliko ima riječi koje se ponavljaju te koliko puta se svaka od njih ponavlja?\n",
" + Provjerite koja je najduža, a koja najkraća riječ."
]
},
{
"cell_type": "code",
"execution_count": 123,
"id": "c5688f5a",
"metadata": {},
"outputs": [],
"source": [
"tekst = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'"
]
},
{
"cell_type": "code",
"execution_count": 124,
"id": "ff28ef89",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'"
]
},
"execution_count": 124,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tekst"
]
},
{
"cell_type": "code",
"execution_count": 125,
"id": "ea2996ff",
"metadata": {},
"outputs": [],
"source": [
"lista_rijeci = tekst.split()"
]
},
{
"cell_type": "code",
"execution_count": 127,
"id": "46758b55",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['lorem',\n",
" 'ipsum',\n",
" 'dolor',\n",
" 'sit',\n",
" 'amet',\n",
" 'consectetur',\n",
" 'adipiscing',\n",
" 'elit',\n",
" 'sed',\n",
" 'do',\n",
" 'eiusmod',\n",
" 'tempor',\n",
" 'incididunt',\n",
" 'ut',\n",
" 'labore',\n",
" 'et',\n",
" 'dolore',\n",
" 'magna',\n",
" 'aliqua',\n",
" 'ut',\n",
" 'enim',\n",
" 'ad',\n",
" 'minim',\n",
" 'veniam',\n",
" 'quis',\n",
" 'nostrud',\n",
" 'exercitation',\n",
" 'ullamco',\n",
" 'laboris',\n",
" 'nisi',\n",
" 'ut',\n",
" 'aliquip',\n",
" 'ex',\n",
" 'ea',\n",
" 'commodo',\n",
" 'consequat',\n",
" 'duis',\n",
" 'aute',\n",
" 'irure',\n",
" 'dolor',\n",
" 'in',\n",
" 'reprehenderit',\n",
" 'in',\n",
" 'voluptate',\n",
" 'velit',\n",
" 'esse',\n",
" 'cillum',\n",
" 'dolore',\n",
" 'eu',\n",
" 'fugiat',\n",
" 'nulla',\n",
" 'pariatur',\n",
" 'excepteur',\n",
" 'sint',\n",
" 'occaecat',\n",
" 'cupidatat',\n",
" 'non',\n",
" 'proident',\n",
" 'sunt',\n",
" 'in',\n",
" 'culpa',\n",
" 'qui',\n",
" 'officia',\n",
" 'deserunt',\n",
" 'mollit',\n",
" 'anim',\n",
" 'id',\n",
" 'est',\n",
" 'laborum']"
]
},
"execution_count": 127,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import re\n",
"lista_rijeci_cisto = []\n",
"for rijec in lista_rijeci:\n",
" rijec = re.sub('[,.]','',rijec)\n",
" rijec = rijec.lower()\n",
" lista_rijeci_cisto.append(rijec)\n",
"lista_rijeci_cisto"
]
},
{
"cell_type": "code",
"execution_count": 128,
"id": "a8056045",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 lorem\n",
"1 ipsum\n",
"2 dolor\n",
"3 sit\n",
"4 amet\n",
"5 consectetur\n",
"6 adipiscing\n",
"7 elit\n",
"8 sed\n",
"9 do\n",
"10 eiusmod\n",
"11 tempor\n",
"12 incididunt\n",
"13 ut\n",
"14 labore\n",
"15 et\n",
"16 dolore\n",
"17 magna\n",
"18 aliqua\n",
"19 ut\n",
"20 enim\n",
"21 ad\n",
"22 minim\n",
"23 veniam\n",
"24 quis\n",
"25 nostrud\n",
"26 exercitation\n",
"27 ullamco\n",
"28 laboris\n",
"29 nisi\n",
"30 ut\n",
"31 aliquip\n",
"32 ex\n",
"33 ea\n",
"34 commodo\n",
"35 consequat\n",
"36 duis\n",
"37 aute\n",
"38 irure\n",
"39 dolor\n",
"40 in\n",
"41 reprehenderit\n",
"42 in\n",
"43 voluptate\n",
"44 velit\n",
"45 esse\n",
"46 cillum\n",
"47 dolore\n",
"48 eu\n",
"49 fugiat\n",
"50 nulla\n",
"51 pariatur\n",
"52 excepteur\n",
"53 sint\n",
"54 occaecat\n",
"55 cupidatat\n",
"56 non\n",
"57 proident\n",
"58 sunt\n",
"59 in\n",
"60 culpa\n",
"61 qui\n",
"62 officia\n",
"63 deserunt\n",
"64 mollit\n",
"65 anim\n",
"66 id\n",
"67 est\n",
"68 laborum\n",
"Name: Latinske riječi, dtype: object"
]
},
"execution_count": 128,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_rijeci = pd.Series(lista_rijeci_cisto, name='Latinske riječi')\n",
"serija_rijeci"
]
},
{
"cell_type": "code",
"execution_count": 130,
"id": "38b316cf",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"41 13\n",
"Name: Latinske riječi, dtype: int64"
]
},
"execution_count": 130,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_rijeci.apply(len).nlargest(1)"
]
},
{
"cell_type": "code",
"execution_count": 142,
"id": "1c1d5e3c",
"metadata": {},
"outputs": [],
"source": [
"serija_kratke = serija_rijeci.apply(len).nsmallest(14)"
]
},
{
"cell_type": "code",
"execution_count": 143,
"id": "aa525d64",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"9 2\n",
"13 2\n",
"15 2\n",
"19 2\n",
"21 2\n",
"30 2\n",
"32 2\n",
"33 2\n",
"40 2\n",
"42 2\n",
"48 2\n",
"59 2\n",
"66 2\n",
"3 3\n",
"Name: Latinske riječi, dtype: int64"
]
},
"execution_count": 143,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"serija_kratke # ispisati sve riječi od 2 slova (sve najkraće riječi)"
]
},
{
"cell_type": "code",
"execution_count": 145,
"id": "a5a654c3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]"
]
},
"execution_count": 145,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0fadaf5f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}