diff --git a/PythonAI/.gitignore b/PythonAI/.gitignore new file mode 100644 index 0000000..e902b72 --- /dev/null +++ b/PythonAI/.gitignore @@ -0,0 +1 @@ +**/.ipynb_checkpoints diff --git a/PythonAI/JupyterLab/PythonAI_01.ipynb b/PythonAI/JupyterLab/PythonAI_01.ipynb new file mode 100644 index 0000000..8409bd5 --- /dev/null +++ b/PythonAI/JupyterLab/PythonAI_01.ipynb @@ -0,0 +1,1795 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "937a6197-91e0-48f6-ba48-2aba923698a6", + "metadata": {}, + "source": [ + "# PythonAI" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "e1b6fa60-9b9e-4647-ab72-29b3eb0a92d2", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "44c4e5ed-7975-49f9-b487-4fba07e0b300", + "metadata": {}, + "outputs": [], + "source": [ + "data = np.genfromtxt(\"/home/sasza/Pobrane/AAPL_stock_price_example.csv\", delimiter=',', usecols=(1), names=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "3dc69a27-1354-4381-9cec-673a46d7d8ac", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[90, 85, 88],\n", + " [72, 78, 80],\n", + " [95, 92, 93]])" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# uczniowie, wyniki testu\n", + "oceny = np.array([\n", + " [90,85,88],\n", + " [72,78,80],\n", + " [95,92,93]\n", + "])\n", + "oceny" + ] + }, + { + "cell_type": "markdown", + "id": "61187ee7-a773-4fb5-b129-158061a76c81", + "metadata": {}, + "source": [ + "# Maski logiczne\n", + "będą powszechnie wykorzystane w Pandas" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "4c7d82b9-9730-4760-97bb-f3de73570934", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[False False True]\n", + " [ True False True]\n", + " [ True True True]]\n", + "[ 4 6 12 123 13 3123]\n" + ] + } + ], + "source": [ + "# maski logiczne\n", + "tab = np.array([\n", + " [2,3,4],\n", + " [6,2,12],\n", + " [123,13,3123]\n", + "])\n", + "\n", + "maska = tab > 3\n", + "print(maska)\n", + "print(tab[maska])" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "637d3ad3-9995-417a-900b-54815a18102a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([2, 3, 4, 2])" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tab[(tab > 2) & (tab < 7)]\n", + "tab[~(tab > 4)]" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "56012b75-9413-462a-9244-8b3699b32d1a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([88, 91, 0, 75, 99, 0])" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "w = np.array([88,91,-1,75,99,-5])\n", + "w * (w>=0)" + ] + }, + { + "cell_type": "markdown", + "id": "e0a6bfd9-1e5a-4dc8-8f80-f73641a1b336", + "metadata": {}, + "source": [ + "# Pandas" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "e052d5de-d25e-4cb0-a4ad-60aa1c7ba539", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2.2.3\n" + ] + } + ], + "source": [ + "print(pd.__version__)" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "61c1cf75-c094-429b-8777-728a16036d68", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " product a product b product c\n", + "Kielce 13 20 200\n", + "Łódź 20 30 10\n", + "Kraków 0 10 0\n", + "Poznań 10 1 -3\n", + "product a 20\n", + "product b 30\n", + "product c 10\n", + "Name: Łódź, dtype: int64\n" + ] + } + ], + "source": [ + "product_data = {\n", + " 'product a': [13,20,0,10],\n", + " 'product b': [20,30,10,1],\n", + " 'product c': [200,10,0,-3],\n", + "}\n", + "\n", + "dane_sprzedazowe = pd.DataFrame(product_data, index=[\"Kielce\",\"Łódź\", \"Kraków\", \"Poznań\"])\n", + "print(dane_sprzedazowe)\n", + "print(dane_sprzedazowe.loc['Łódź'])" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "id": "5e495c66-927f-4ee6-ae52-6e02c9ad138e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Date Close\n", + "0 2019-01-02 157.919998\n", + "1 2019-01-03 142.190002\n", + "2 2019-01-04 148.259995\n", + "3 2019-01-07 147.929993\n", + "4 2019-01-08 150.750000\n", + ".. ... ...\n", + "224 2019-11-20 263.190002\n", + "225 2019-11-21 262.010010\n", + "226 2019-11-22 261.779999\n", + "227 2019-11-25 266.369995\n", + "228 2019-11-26 264.290009\n", + "\n", + "[229 rows x 2 columns]\n", + "\n", + "RangeIndex: 229 entries, 0 to 228\n", + "Data columns (total 2 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 Date 229 non-null object \n", + " 1 Close 229 non-null float64\n", + "dtypes: float64(1), object(1)\n", + "memory usage: 3.7+ KB\n", + "None\n", + " Close\n", + "count 229.000000\n", + "mean 201.477598\n", + "std 28.246961\n", + "min 142.190002\n", + "25% 182.539993\n", + "50% 200.720001\n", + "75% 213.279999\n", + "max 267.100006\n", + "(229, 2)\n", + "Index(['Date', 'Close'], dtype='object')\n", + " Date Close\n", + "0 False False\n", + "1 False False\n", + "2 False False\n", + "3 False False\n", + "4 False False\n", + ".. ... ...\n", + "224 False False\n", + "225 False False\n", + "226 False False\n", + "227 False False\n", + "228 False False\n", + "\n", + "[229 rows x 2 columns]\n" + ] + } + ], + "source": [ + "data = pd.read_csv(\"data/AAPL_stock_price_example.csv\")\n", + "# data = pd.read_csv(\"./AAPL_stock_price_example.csv\", parse_dates=[\"Date\")\n", + "print(data)\n", + "print(data.info())\n", + "print(data.describe())\n", + "print(data.shape)\n", + "print(data.columns)\n", + "print(data.isnull())" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "id": "d016fb3a-efce-407c-afc2-619380fea702", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
productwholesale_pricemsrpqty_orderedqty_shipped
0skippys_dream8.9918.38100100
1just_the_beef4.9910.43200195
2potatos_and_lamb5.1911.435050
3turkey_and_cranberries5.9812.005050
4roasted_duck9.5917.481515
\n", + "
" + ], + "text/plain": [ + " product wholesale_price msrp qty_ordered qty_shipped\n", + "0 skippys_dream 8.99 18.38 100 100\n", + "1 just_the_beef 4.99 10.43 200 195\n", + "2 potatos_and_lamb 5.19 11.43 50 50\n", + "3 turkey_and_cranberries 5.98 12.00 50 50\n", + "4 roasted_duck 9.59 17.48 15 15" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data = pd.read_excel(\"data/dog_food_orders.xlsx\")\n", + "data" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "id": "755eaff8-b0a2-4d2f-aaba-590441eaa748", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['dteday', 'hr', 'cnt'], dtype='object')" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import sqlite3\n", + "con = sqlite3.connect(\"data/bike_share.db\")\n", + "data = pd.read_sql(\"SELECT * FROM rentals\", con)\n", + "data = data.set_index(\"index\")\n", + "data" + ] + }, + { + "cell_type": "code", + "execution_count": 139, + "id": "c08a3987-83b3-4314-a2a5-ed0da13d11ac", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
NameTelephoneEmailOffice
0Dr. Sally555-1234sally@calpoly.edu12-34
1Dr. Steve555-5678steve@calpoly.edu56-78
2Dr. Kathy555-9012kathy@calpoly.edu90-123
\n", + "
" + ], + "text/plain": [ + " Name Telephone Email Office\n", + "0 Dr. Sally 555-1234 sally@calpoly.edu 12-34\n", + "1 Dr. Steve 555-5678 steve@calpoly.edu 56-78\n", + "2 Dr. Kathy 555-9012 kathy@calpoly.edu 90-123" + ] + }, + "execution_count": 139, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data = pd.read_html(\"https://afd.calpoly.edu/web/sample-tables\")\n", + "data[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 163, + "id": "e06d2078-5eff-40c8-945e-096b1bbd73b8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 163, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import requests\n", + "import datetime as dt\n", + "yesterday = dt.date.today() - dt.timedelta(days=1)\n", + "api = \"https://earthquake.usgs.gov/fdsnws/event/1/query\"\n", + "payload = {\n", + " \"format\": \"geojson\",\n", + " \"starttime\": yesterday - dt.timedelta(days=7),\n", + " \"endtime\": yesterday\n", + "}\n", + "response = requests.get(api, params=payload)\n", + "response" + ] + }, + { + "cell_type": "code", + "execution_count": 194, + "id": "5ca9c016-fbb6-4b1d-a424-9a396152857b", + "metadata": {}, + "outputs": [], + "source": [ + "json = response.json()\n", + "\n", + "data = [quake['properties'] for quake in json['features']]\n", + "data = pd.DataFrame(data)\n", + "\n", + "# data.sort_values(by='mag', ascending=False)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 199, + "id": "53002cd9-4747-48f9-ba75-58bd367f943b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
magplacetimeupdatedtzurldetailfeltcdimmi...idssourcestypesnstdminrmsgapmagTypetypetitle
01.565 km NNW of Boron, CA2025-03-23 23:56:23.0002025-03-24 00:01:09.995Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,ci40908351,,ci,,nearby-cities,origin,phase-data,scitech-link,36.00.1100000.2040.0mlearthquakeM 1.6 - 5 km NNW of Boron, CA
11.6031 km NW of Toyah, Texas2025-03-23 23:55:05.2462025-03-24 15:17:33.050Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,tx2025ftvc,,tx,,origin,phase-data,14.00.0000000.2062.0mlearthquakeM 1.6 - 31 km NW of Toyah, Texas
21.706 km NNE of Windsor, CA2025-03-23 23:52:39.9602025-03-25 12:07:17.366Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,nc75154137,,nc,,focal-mechanism,nearby-cities,origin,phase-da...64.00.0741300.0845.0mdearthquakeM 1.7 - 6 km NNE of Windsor, CA
35.10154 km ESE of Neiafu, Tonga2025-03-23 23:36:24.2132025-03-24 01:09:53.040Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,us7000pm4g,,us,,origin,phase-data,58.02.5670000.8862.0mbearthquakeM 5.1 - 154 km ESE of Neiafu, Tonga
41.1514 km ENE of Indio, CA2025-03-23 23:35:52.8102025-03-23 23:40:43.046Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,ci40908335,,ci,,nearby-cities,origin,phase-data,scitech-link,39.00.1184000.1947.0mlearthquakeM 1.2 - 14 km ENE of Indio, CA
..................................................................
23281.8070 km SE of Pedro Bay, Alaska2025-03-17 00:10:04.9352025-03-17 00:11:59.955Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,ak0253howj2l,,ak,,origin,phase-data,NaNNaN0.45NaNmlearthquakeM 1.8 - 70 km SE of Pedro Bay, Alaska
23291.752 km of The Geysers, CA2025-03-17 00:09:46.3902025-03-17 02:47:21.992Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,nc75149791,,nc,,nearby-cities,origin,phase-data,scitech-link,21.00.0075180.0267.0mdearthquakeM 1.8 - 2 km of The Geysers, CA
23301.341 km NNW of The Geysers, CA2025-03-17 00:08:45.2802025-03-17 02:22:19.952Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,nc75149786,,nc,,nearby-cities,origin,phase-data,scitech-link,11.00.0132700.0399.0mdearthquakeM 1.3 - 1 km NNW of The Geysers, CA
23310.654 km NNW of The Geysers, CA2025-03-17 00:05:59.3602025-03-17 17:56:00.796Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,nc75149781,,nc,,nearby-cities,origin,phase-data,scitech-link,15.00.0097860.0180.0mdearthquakeM 0.7 - 4 km NNW of The Geysers, CA
23321.6057 km S of Whites City, New Mexico2025-03-17 00:04:47.9522025-03-18 20:40:34.369Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,tx2025fhax,,tx,,origin,phase-data,17.00.1000000.3069.0mlearthquakeM 1.6 - 57 km S of Whites City, New Mexico
\n", + "

2333 rows × 26 columns

\n", + "
" + ], + "text/plain": [ + " mag place time \\\n", + "0 1.56 5 km NNW of Boron, CA 2025-03-23 23:56:23.000 \n", + "1 1.60 31 km NW of Toyah, Texas 2025-03-23 23:55:05.246 \n", + "2 1.70 6 km NNE of Windsor, CA 2025-03-23 23:52:39.960 \n", + "3 5.10 154 km ESE of Neiafu, Tonga 2025-03-23 23:36:24.213 \n", + "4 1.15 14 km ENE of Indio, CA 2025-03-23 23:35:52.810 \n", + "... ... ... ... \n", + "2328 1.80 70 km SE of Pedro Bay, Alaska 2025-03-17 00:10:04.935 \n", + "2329 1.75 2 km of The Geysers, CA 2025-03-17 00:09:46.390 \n", + "2330 1.34 1 km NNW of The Geysers, CA 2025-03-17 00:08:45.280 \n", + "2331 0.65 4 km NNW of The Geysers, CA 2025-03-17 00:05:59.360 \n", + "2332 1.60 57 km S of Whites City, New Mexico 2025-03-17 00:04:47.952 \n", + "\n", + " updated tz \\\n", + "0 2025-03-24 00:01:09.995 None \n", + "1 2025-03-24 15:17:33.050 None \n", + "2 2025-03-25 12:07:17.366 None \n", + "3 2025-03-24 01:09:53.040 None \n", + "4 2025-03-23 23:40:43.046 None \n", + "... ... ... \n", + "2328 2025-03-17 00:11:59.955 None \n", + "2329 2025-03-17 02:47:21.992 None \n", + "2330 2025-03-17 02:22:19.952 None \n", + "2331 2025-03-17 17:56:00.796 None \n", + "2332 2025-03-18 20:40:34.369 None \n", + "\n", + " url \\\n", + "0 https://earthquake.usgs.gov/earthquakes/eventp... \n", + "1 https://earthquake.usgs.gov/earthquakes/eventp... \n", + "2 https://earthquake.usgs.gov/earthquakes/eventp... \n", + "3 https://earthquake.usgs.gov/earthquakes/eventp... \n", + "4 https://earthquake.usgs.gov/earthquakes/eventp... \n", + "... ... \n", + "2328 https://earthquake.usgs.gov/earthquakes/eventp... \n", + "2329 https://earthquake.usgs.gov/earthquakes/eventp... \n", + "2330 https://earthquake.usgs.gov/earthquakes/eventp... \n", + "2331 https://earthquake.usgs.gov/earthquakes/eventp... \n", + "2332 https://earthquake.usgs.gov/earthquakes/eventp... \n", + "\n", + " detail felt cdi mmi ... \\\n", + "0 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "1 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "2 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "3 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "4 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "... ... ... ... ... ... \n", + "2328 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "2329 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "2330 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "2331 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "2332 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "\n", + " ids sources \\\n", + "0 ,ci40908351, ,ci, \n", + "1 ,tx2025ftvc, ,tx, \n", + "2 ,nc75154137, ,nc, \n", + "3 ,us7000pm4g, ,us, \n", + "4 ,ci40908335, ,ci, \n", + "... ... ... \n", + "2328 ,ak0253howj2l, ,ak, \n", + "2329 ,nc75149791, ,nc, \n", + "2330 ,nc75149786, ,nc, \n", + "2331 ,nc75149781, ,nc, \n", + "2332 ,tx2025fhax, ,tx, \n", + "\n", + " types nst dmin rms \\\n", + "0 ,nearby-cities,origin,phase-data,scitech-link, 36.0 0.110000 0.20 \n", + "1 ,origin,phase-data, 14.0 0.000000 0.20 \n", + "2 ,focal-mechanism,nearby-cities,origin,phase-da... 64.0 0.074130 0.08 \n", + "3 ,origin,phase-data, 58.0 2.567000 0.88 \n", + "4 ,nearby-cities,origin,phase-data,scitech-link, 39.0 0.118400 0.19 \n", + "... ... ... ... ... \n", + "2328 ,origin,phase-data, NaN NaN 0.45 \n", + "2329 ,nearby-cities,origin,phase-data,scitech-link, 21.0 0.007518 0.02 \n", + "2330 ,nearby-cities,origin,phase-data,scitech-link, 11.0 0.013270 0.03 \n", + "2331 ,nearby-cities,origin,phase-data,scitech-link, 15.0 0.009786 0.01 \n", + "2332 ,origin,phase-data, 17.0 0.100000 0.30 \n", + "\n", + " gap magType type title \n", + "0 40.0 ml earthquake M 1.6 - 5 km NNW of Boron, CA \n", + "1 62.0 ml earthquake M 1.6 - 31 km NW of Toyah, Texas \n", + "2 45.0 md earthquake M 1.7 - 6 km NNE of Windsor, CA \n", + "3 62.0 mb earthquake M 5.1 - 154 km ESE of Neiafu, Tonga \n", + "4 47.0 ml earthquake M 1.2 - 14 km ENE of Indio, CA \n", + "... ... ... ... ... \n", + "2328 NaN ml earthquake M 1.8 - 70 km SE of Pedro Bay, Alaska \n", + "2329 67.0 md earthquake M 1.8 - 2 km of The Geysers, CA \n", + "2330 99.0 md earthquake M 1.3 - 1 km NNW of The Geysers, CA \n", + "2331 80.0 md earthquake M 0.7 - 4 km NNW of The Geysers, CA \n", + "2332 69.0 ml earthquake M 1.6 - 57 km S of Whites City, New Mexico \n", + "\n", + "[2333 rows x 26 columns]" + ] + }, + "execution_count": 199, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data['time'] = pd.to_datetime(data.time, unit='ms')\n", + "data['updated'] = pd.to_datetime(data.updated, unit='ms')\n", + "data" + ] + }, + { + "cell_type": "code", + "execution_count": 208, + "id": "5ad6604e-4dd4-40db-8758-aca82675baf2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
placetzurldetailalertstatusnetcodeidssourcestypesmagTypetypetitle
count233302333233317233323332333233323332333233323332333
unique14300233323331316233123335437842051
top9 km NW of The Geysers, CANaNhttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...greenreviewednc2025frug,tx2025fhax,,nc,,origin,phase-data,mlearthquakeM 0.8 - 7 km NW of The Geysers, CA
freq36NaN111716035442153312721470227814
\n", + "
" + ], + "text/plain": [ + " place tz \\\n", + "count 2333 0 \n", + "unique 1430 0 \n", + "top 9 km NW of The Geysers, CA NaN \n", + "freq 36 NaN \n", + "\n", + " url \\\n", + "count 2333 \n", + "unique 2333 \n", + "top https://earthquake.usgs.gov/earthquakes/eventp... \n", + "freq 1 \n", + "\n", + " detail alert status \\\n", + "count 2333 17 2333 \n", + "unique 2333 1 3 \n", + "top https://earthquake.usgs.gov/fdsnws/event/1/que... green reviewed \n", + "freq 1 17 1603 \n", + "\n", + " net code ids sources types magType \\\n", + "count 2333 2333 2333 2333 2333 2333 \n", + "unique 16 2331 2333 54 37 8 \n", + "top nc 2025frug ,tx2025fhax, ,nc, ,origin,phase-data, ml \n", + "freq 544 2 1 533 1272 1470 \n", + "\n", + " type title \n", + "count 2333 2333 \n", + "unique 4 2051 \n", + "top earthquake M 0.8 - 7 km NW of The Geysers, CA \n", + "freq 2278 14 " + ] + }, + "execution_count": 208, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.describe(percentiles=[0.1,0.5,0.9])\n", + "data.describe(include='all')\n", + "data.describe(include=object)" + ] + }, + { + "cell_type": "code", + "execution_count": 213, + "id": "b93408b0-5bdc-4350-8894-30d6fe199b92", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "type\n", + "earthquake 2278\n", + "quarry blast 33\n", + "explosion 19\n", + "ice quake 3\n", + "Name: count, dtype: int64" + ] + }, + "execution_count": 213, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.type.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3e97cee2-0491-4ed2-84f1-b72f7b986fa2", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 197, + "id": "ca04e8f9-2005-432b-8607-a391f65eafb8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
magplacetimeupdatedtzurldetailfeltcdimmi...idssourcestypesnstdminrmsgapmagTypetypetitle
01.565 km NNW of Boron, CA2025-03-23 23:56:23.0001742774469995Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,ci40908351,,ci,,nearby-cities,origin,phase-data,scitech-link,36.00.1100000.2040.0mlearthquakeM 1.6 - 5 km NNW of Boron, CA
11.6031 km NW of Toyah, Texas2025-03-23 23:55:05.2461742829453050Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,tx2025ftvc,,tx,,origin,phase-data,14.00.0000000.2062.0mlearthquakeM 1.6 - 31 km NW of Toyah, Texas
21.706 km NNE of Windsor, CA2025-03-23 23:52:39.9601742904437366Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,nc75154137,,nc,,focal-mechanism,nearby-cities,origin,phase-da...64.00.0741300.0845.0mdearthquakeM 1.7 - 6 km NNE of Windsor, CA
35.10154 km ESE of Neiafu, Tonga2025-03-23 23:36:24.2131742778593040Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,us7000pm4g,,us,,origin,phase-data,58.02.5670000.8862.0mbearthquakeM 5.1 - 154 km ESE of Neiafu, Tonga
41.1514 km ENE of Indio, CA2025-03-23 23:35:52.8101742773243046Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,ci40908335,,ci,,nearby-cities,origin,phase-data,scitech-link,39.00.1184000.1947.0mlearthquakeM 1.2 - 14 km ENE of Indio, CA
..................................................................
23281.8070 km SE of Pedro Bay, Alaska2025-03-17 00:10:04.9351742170319955Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,ak0253howj2l,,ak,,origin,phase-data,NaNNaN0.45NaNmlearthquakeM 1.8 - 70 km SE of Pedro Bay, Alaska
23291.752 km of The Geysers, CA2025-03-17 00:09:46.3901742179641992Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,nc75149791,,nc,,nearby-cities,origin,phase-data,scitech-link,21.00.0075180.0267.0mdearthquakeM 1.8 - 2 km of The Geysers, CA
23301.341 km NNW of The Geysers, CA2025-03-17 00:08:45.2801742178139952Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,nc75149786,,nc,,nearby-cities,origin,phase-data,scitech-link,11.00.0132700.0399.0mdearthquakeM 1.3 - 1 km NNW of The Geysers, CA
23310.654 km NNW of The Geysers, CA2025-03-17 00:05:59.3601742234160796Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,nc75149781,,nc,,nearby-cities,origin,phase-data,scitech-link,15.00.0097860.0180.0mdearthquakeM 0.7 - 4 km NNW of The Geysers, CA
23321.6057 km S of Whites City, New Mexico2025-03-17 00:04:47.9521742330434369Nonehttps://earthquake.usgs.gov/earthquakes/eventp...https://earthquake.usgs.gov/fdsnws/event/1/que...NaNNaNNaN...,tx2025fhax,,tx,,origin,phase-data,17.00.1000000.3069.0mlearthquakeM 1.6 - 57 km S of Whites City, New Mexico
\n", + "

2333 rows × 26 columns

\n", + "
" + ], + "text/plain": [ + " mag place time \\\n", + "0 1.56 5 km NNW of Boron, CA 2025-03-23 23:56:23.000 \n", + "1 1.60 31 km NW of Toyah, Texas 2025-03-23 23:55:05.246 \n", + "2 1.70 6 km NNE of Windsor, CA 2025-03-23 23:52:39.960 \n", + "3 5.10 154 km ESE of Neiafu, Tonga 2025-03-23 23:36:24.213 \n", + "4 1.15 14 km ENE of Indio, CA 2025-03-23 23:35:52.810 \n", + "... ... ... ... \n", + "2328 1.80 70 km SE of Pedro Bay, Alaska 2025-03-17 00:10:04.935 \n", + "2329 1.75 2 km of The Geysers, CA 2025-03-17 00:09:46.390 \n", + "2330 1.34 1 km NNW of The Geysers, CA 2025-03-17 00:08:45.280 \n", + "2331 0.65 4 km NNW of The Geysers, CA 2025-03-17 00:05:59.360 \n", + "2332 1.60 57 km S of Whites City, New Mexico 2025-03-17 00:04:47.952 \n", + "\n", + " updated tz url \\\n", + "0 1742774469995 None https://earthquake.usgs.gov/earthquakes/eventp... \n", + "1 1742829453050 None https://earthquake.usgs.gov/earthquakes/eventp... \n", + "2 1742904437366 None https://earthquake.usgs.gov/earthquakes/eventp... \n", + "3 1742778593040 None https://earthquake.usgs.gov/earthquakes/eventp... \n", + "4 1742773243046 None https://earthquake.usgs.gov/earthquakes/eventp... \n", + "... ... ... ... \n", + "2328 1742170319955 None https://earthquake.usgs.gov/earthquakes/eventp... \n", + "2329 1742179641992 None https://earthquake.usgs.gov/earthquakes/eventp... \n", + "2330 1742178139952 None https://earthquake.usgs.gov/earthquakes/eventp... \n", + "2331 1742234160796 None https://earthquake.usgs.gov/earthquakes/eventp... \n", + "2332 1742330434369 None https://earthquake.usgs.gov/earthquakes/eventp... \n", + "\n", + " detail felt cdi mmi ... \\\n", + "0 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "1 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "2 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "3 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "4 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "... ... ... ... ... ... \n", + "2328 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "2329 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "2330 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "2331 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "2332 https://earthquake.usgs.gov/fdsnws/event/1/que... NaN NaN NaN ... \n", + "\n", + " ids sources \\\n", + "0 ,ci40908351, ,ci, \n", + "1 ,tx2025ftvc, ,tx, \n", + "2 ,nc75154137, ,nc, \n", + "3 ,us7000pm4g, ,us, \n", + "4 ,ci40908335, ,ci, \n", + "... ... ... \n", + "2328 ,ak0253howj2l, ,ak, \n", + "2329 ,nc75149791, ,nc, \n", + "2330 ,nc75149786, ,nc, \n", + "2331 ,nc75149781, ,nc, \n", + "2332 ,tx2025fhax, ,tx, \n", + "\n", + " types nst dmin rms \\\n", + "0 ,nearby-cities,origin,phase-data,scitech-link, 36.0 0.110000 0.20 \n", + "1 ,origin,phase-data, 14.0 0.000000 0.20 \n", + "2 ,focal-mechanism,nearby-cities,origin,phase-da... 64.0 0.074130 0.08 \n", + "3 ,origin,phase-data, 58.0 2.567000 0.88 \n", + "4 ,nearby-cities,origin,phase-data,scitech-link, 39.0 0.118400 0.19 \n", + "... ... ... ... ... \n", + "2328 ,origin,phase-data, NaN NaN 0.45 \n", + "2329 ,nearby-cities,origin,phase-data,scitech-link, 21.0 0.007518 0.02 \n", + "2330 ,nearby-cities,origin,phase-data,scitech-link, 11.0 0.013270 0.03 \n", + "2331 ,nearby-cities,origin,phase-data,scitech-link, 15.0 0.009786 0.01 \n", + "2332 ,origin,phase-data, 17.0 0.100000 0.30 \n", + "\n", + " gap magType type title \n", + "0 40.0 ml earthquake M 1.6 - 5 km NNW of Boron, CA \n", + "1 62.0 ml earthquake M 1.6 - 31 km NW of Toyah, Texas \n", + "2 45.0 md earthquake M 1.7 - 6 km NNE of Windsor, CA \n", + "3 62.0 mb earthquake M 5.1 - 154 km ESE of Neiafu, Tonga \n", + "4 47.0 ml earthquake M 1.2 - 14 km ENE of Indio, CA \n", + "... ... ... ... ... \n", + "2328 NaN ml earthquake M 1.8 - 70 km SE of Pedro Bay, Alaska \n", + "2329 67.0 md earthquake M 1.8 - 2 km of The Geysers, CA \n", + "2330 99.0 md earthquake M 1.3 - 1 km NNW of The Geysers, CA \n", + "2331 80.0 md earthquake M 0.7 - 4 km NNW of The Geysers, CA \n", + "2332 69.0 ml earthquake M 1.6 - 57 km S of Whites City, New Mexico \n", + "\n", + "[2333 rows x 26 columns]" + ] + }, + "execution_count": 197, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.to_csv(\"data/out.csv\")" + ] + }, + { + "cell_type": "markdown", + "id": "aeea3f8b-4856-4ba5-83dd-f6b0f4aa3747", + "metadata": { + "jp-MarkdownHeadingCollapsed": true + }, + "source": [ + "# Losowość" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "id": "d114c181-cb51-4e7d-ab7c-e1033c6f1916", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0 0.068324\n", + "1 0.228807\n", + "2 0.424159\n", + "3 0.288747\n", + "4 0.091950\n", + "5 0.017583\n", + "6 0.832726\n", + "7 0.191866\n", + "8 0.969317\n", + "9 0.795694\n", + "10 0.385554\n", + "11 0.614211\n", + "12 0.881981\n", + "13 0.157185\n", + "14 0.908872\n", + "dtype: float64" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import time\n", + "np.random.seed(int(time.time()))\n", + "x = np.random.rand(15)\n", + "pd.Series(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "id": "b5f7817b-a68d-4c6a-a16d-ffbe25e76156", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
randomtexttruth
2025-03-010.693064fooTrue
2025-03-020.473443barTrue
2025-03-030.877936bazTrue
\n", + "
" + ], + "text/plain": [ + " random text truth\n", + "2025-03-01 0.693064 foo True\n", + "2025-03-02 0.473443 bar True\n", + "2025-03-03 0.877936 baz True" + ] + }, + "execution_count": 106, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data = pd.DataFrame({\n", + " \"random\": np.random.rand(5),\n", + " \"text\": [\"foo\", \"bar\", \"baz\", \"car\", \"txt\"],\n", + " \"truth\": [np.random.choice((True, False)) for _ in range(5)]\n", + "}, index = pd.date_range(\"2025-03-01\", periods=5, freq=\"D\")\n", + ")\n", + "\n", + "data[data[\"truth\"] == True]" + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "id": "c8f5fba4-76fe-4b0a-bbc0-e2c5114a769b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
012
0000
1112
2244
3396
44168
\n", + "
" + ], + "text/plain": [ + " 0 1 2\n", + "0 0 0 0\n", + "1 1 1 2\n", + "2 2 4 4\n", + "3 3 9 6\n", + "4 4 16 8" + ] + }, + "execution_count": 118, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tuple = [(n, n**2, n*2) for n in range(5)]\n", + "pd.DataFrame(tuple)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c5d2e71f-0ce7-4329-afad-bb50a5f31dc2", + "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.12.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/PythonAI/JupyterLab/data/AAPL_stock_price_example.csv b/PythonAI/JupyterLab/data/AAPL_stock_price_example.csv new file mode 100644 index 0000000..8679cb0 --- /dev/null +++ b/PythonAI/JupyterLab/data/AAPL_stock_price_example.csv @@ -0,0 +1,230 @@ +Date,Close +2019-01-02,157.919998 +2019-01-03,142.190002 +2019-01-04,148.259995 +2019-01-07,147.929993 +2019-01-08,150.75 +2019-01-09,153.309998 +2019-01-10,153.800003 +2019-01-11,152.289993 +2019-01-14,150 +2019-01-15,153.070007 +2019-01-16,154.940002 +2019-01-17,155.860001 +2019-01-18,156.820007 +2019-01-22,153.300003 +2019-01-23,153.919998 +2019-01-24,152.699997 +2019-01-25,157.759995 +2019-01-28,156.300003 +2019-01-29,154.679993 +2019-01-30,165.25 +2019-01-31,166.440002 +2019-02-01,166.520004 +2019-02-04,171.25 +2019-02-05,174.179993 +2019-02-06,174.240005 +2019-02-07,170.940002 +2019-02-08,170.410004 +2019-02-11,169.429993 +2019-02-12,170.889999 +2019-02-13,170.179993 +2019-02-14,170.800003 +2019-02-15,170.419998 +2019-02-19,170.929993 +2019-02-20,172.029999 +2019-02-21,171.059998 +2019-02-22,172.970001 +2019-02-25,174.229996 +2019-02-26,174.330002 +2019-02-27,174.869995 +2019-02-28,173.149994 +2019-03-01,174.970001 +2019-03-04,175.850006 +2019-03-05,175.529999 +2019-03-06,174.520004 +2019-03-07,172.5 +2019-03-08,172.910004 +2019-03-11,178.899994 +2019-03-12,180.910004 +2019-03-13,181.710007 +2019-03-14,183.729996 +2019-03-15,186.119995 +2019-03-18,188.020004 +2019-03-19,186.529999 +2019-03-20,188.160004 +2019-03-21,195.089996 +2019-03-22,191.050003 +2019-03-25,188.740005 +2019-03-26,186.789993 +2019-03-27,188.470001 +2019-03-28,188.720001 +2019-03-29,189.949997 +2019-04-01,191.240005 +2019-04-02,194.020004 +2019-04-03,195.350006 +2019-04-04,195.690002 +2019-04-05,197 +2019-04-08,200.100006 +2019-04-09,199.5 +2019-04-10,200.619995 +2019-04-11,198.949997 +2019-04-12,198.869995 +2019-04-15,199.229996 +2019-04-16,199.25 +2019-04-17,203.130005 +2019-04-18,203.860001 +2019-04-22,204.529999 +2019-04-23,207.479996 +2019-04-24,207.160004 +2019-04-25,205.279999 +2019-04-26,204.300003 +2019-04-29,204.610001 +2019-04-30,200.669998 +2019-05-01,210.520004 +2019-05-02,209.149994 +2019-05-03,211.75 +2019-05-06,208.479996 +2019-05-07,202.860001 +2019-05-08,202.899994 +2019-05-09,200.720001 +2019-05-10,197.179993 +2019-05-13,185.720001 +2019-05-14,188.660004 +2019-05-15,190.919998 +2019-05-16,190.080002 +2019-05-17,189 +2019-05-20,183.089996 +2019-05-21,186.600006 +2019-05-22,182.779999 +2019-05-23,179.660004 +2019-05-24,178.970001 +2019-05-28,178.229996 +2019-05-29,177.380005 +2019-05-30,178.300003 +2019-05-31,175.070007 +2019-06-03,173.300003 +2019-06-04,179.639999 +2019-06-05,182.539993 +2019-06-06,185.220001 +2019-06-07,190.149994 +2019-06-10,192.580002 +2019-06-11,194.809998 +2019-06-12,194.190002 +2019-06-13,194.149994 +2019-06-14,192.740005 +2019-06-17,193.889999 +2019-06-18,198.449997 +2019-06-19,197.869995 +2019-06-20,199.460007 +2019-06-21,198.779999 +2019-06-24,198.580002 +2019-06-25,195.570007 +2019-06-26,199.800003 +2019-06-27,199.740005 +2019-06-28,197.919998 +2019-07-01,201.550003 +2019-07-02,202.729996 +2019-07-03,204.410004 +2019-07-05,204.229996 +2019-07-08,200.020004 +2019-07-09,201.240005 +2019-07-10,203.229996 +2019-07-11,201.75 +2019-07-12,203.300003 +2019-07-15,205.210007 +2019-07-16,204.5 +2019-07-17,203.350006 +2019-07-18,205.660004 +2019-07-19,202.589996 +2019-07-22,207.220001 +2019-07-23,208.839996 +2019-07-24,208.669998 +2019-07-25,207.020004 +2019-07-26,207.740005 +2019-07-29,209.679993 +2019-07-30,208.779999 +2019-07-31,213.039993 +2019-08-01,208.429993 +2019-08-02,204.020004 +2019-08-05,193.339996 +2019-08-06,197 +2019-08-07,199.039993 +2019-08-08,203.429993 +2019-08-09,200.990005 +2019-08-12,200.479996 +2019-08-13,208.970001 +2019-08-14,202.75 +2019-08-15,201.740005 +2019-08-16,206.5 +2019-08-19,210.350006 +2019-08-20,210.360001 +2019-08-21,212.639999 +2019-08-22,212.460007 +2019-08-23,202.639999 +2019-08-26,206.490005 +2019-08-27,204.160004 +2019-08-28,205.529999 +2019-08-29,209.009995 +2019-08-30,208.740005 +2019-09-03,205.699997 +2019-09-04,209.190002 +2019-09-05,213.279999 +2019-09-06,213.259995 +2019-09-09,214.169998 +2019-09-10,216.699997 +2019-09-11,223.589996 +2019-09-12,223.089996 +2019-09-13,218.75 +2019-09-16,219.899994 +2019-09-17,220.699997 +2019-09-18,222.770004 +2019-09-19,220.960007 +2019-09-20,217.729996 +2019-09-23,218.720001 +2019-09-24,217.679993 +2019-09-25,221.029999 +2019-09-26,219.889999 +2019-09-27,218.820007 +2019-09-30,223.970001 +2019-10-01,224.589996 +2019-10-02,218.960007 +2019-10-03,220.820007 +2019-10-04,227.009995 +2019-10-07,227.059998 +2019-10-08,224.399994 +2019-10-09,227.029999 +2019-10-10,230.089996 +2019-10-11,236.210007 +2019-10-14,235.869995 +2019-10-15,235.320007 +2019-10-16,234.369995 +2019-10-17,235.279999 +2019-10-18,236.410004 +2019-10-21,240.509995 +2019-10-22,239.960007 +2019-10-23,243.179993 +2019-10-24,243.580002 +2019-10-25,246.580002 +2019-10-28,249.050003 +2019-10-29,243.289993 +2019-10-30,243.259995 +2019-10-31,248.759995 +2019-11-01,255.820007 +2019-11-04,257.5 +2019-11-05,257.130005 +2019-11-06,257.23999 +2019-11-07,259.429993 +2019-11-08,260.140015 +2019-11-11,262.200012 +2019-11-12,261.959991 +2019-11-13,264.470001 +2019-11-14,262.640015 +2019-11-15,265.76001 +2019-11-18,267.100006 +2019-11-19,266.290009 +2019-11-20,263.190002 +2019-11-21,262.01001 +2019-11-22,261.779999 +2019-11-25,266.369995 +2019-11-26,264.290009 \ No newline at end of file diff --git a/PythonAI/JupyterLab/data/bike_share.db b/PythonAI/JupyterLab/data/bike_share.db new file mode 100644 index 0000000..e158e7d Binary files /dev/null and b/PythonAI/JupyterLab/data/bike_share.db differ diff --git a/PythonAI/JupyterLab/data/dog_food_orders.xlsx b/PythonAI/JupyterLab/data/dog_food_orders.xlsx new file mode 100644 index 0000000..00947ec Binary files /dev/null and b/PythonAI/JupyterLab/data/dog_food_orders.xlsx differ diff --git a/PythonAI/JupyterLab/dzien1_numpy_notebook_trener.ipynb b/PythonAI/JupyterLab/dzien1_numpy_notebook_trener.ipynb new file mode 100644 index 0000000..7a13c23 --- /dev/null +++ b/PythonAI/JupyterLab/dzien1_numpy_notebook_trener.ipynb @@ -0,0 +1,226 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d057e434", + "metadata": {}, + "source": [ + "# 🧠 Dzień 1: Środowisko pracy analityka i NumPy\n" + ] + }, + { + "cell_type": "markdown", + "id": "87a3a255", + "metadata": {}, + "source": [ + "## 🔧 Konfiguracja środowiska\n", + "Zainstaluj Anacondę i utwórz środowisko Conda o nazwie `ml-env`:\n", + "\n", + "```bash\n", + "conda create -n ml-env python=3.12\n", + "conda activate ml-env\n", + "```\n", + "\n", + "Możesz także użyć `pip` do instalacji paczek:\n", + "\n", + "```bash\n", + "pip install numpy pandas jupyter\n", + "```\n" + ] + }, + { + "cell_type": "markdown", + "id": "f7fb0290", + "metadata": {}, + "source": [ + "## 📓 Jupyter Notebook – podstawy\n", + "- Komórki kodu i Markdown\n", + "- Skróty klawiszowe (`Ctrl+Enter`, `Shift+Enter`, `A`, `B` itd.)\n", + "\n", + "**Zadanie:** Stwórz komórkę Markdown i wpisz nagłówek oraz listę punktowaną." + ] + }, + { + "cell_type": "markdown", + "id": "18bf84af", + "metadata": {}, + "source": [ + "## 🔢 NumPy – podstawy\n", + "- Tworzenie wektorów i macierzy\n", + "- Operacje matematyczne\n", + "- Wektoryzacja i broadcasting\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "e3bfabbb", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1 2 3]\n", + "[[1 2]\n", + " [3 4]]\n" + ] + } + ], + "source": [ + "# Przykład: stworzenie wektora i macierzy\n", + "import numpy as np\n", + "\n", + "wektor = np.array([1, 2, 3])\n", + "macierz = np.array([[1, 2], [3, 4]])\n", + "print(wektor)\n", + "print(macierz)" + ] + }, + { + "cell_type": "markdown", + "id": "666b0410", + "metadata": {}, + "source": [ + "### ✍️ Zadanie 1\n", + "Stwórz:\n", + "- wektor 1D z liczbami od 10 do 20\n", + "- macierz 3x3 z losowymi liczbami całkowitymi od 0 do 100" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "10555f08", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[10 11 12 13 14 15 16 17 18 19 20]\n", + "[[26 84 24]\n", + " [92 74 70]\n", + " [91 15 14]]\n" + ] + } + ], + "source": [ + "# Zadanie 1 – Przykładowe rozwiązanie\n", + "wektor = np.arange(10, 21)\n", + "macierz = np.random.randint(0, 101, size=(3, 3))\n", + "print(wektor)\n", + "print(macierz)" + ] + }, + { + "cell_type": "markdown", + "id": "3660456f", + "metadata": {}, + "source": [ + "### ✍️ Zadanie 2\n", + "Wykonaj dodawanie, mnożenie i dzielenie elementów dwóch tablic NumPy o takim samym rozmiarze." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "64897ffd", + "metadata": {}, + "outputs": [], + "source": [ + "# Zadanie 2 – Przykładowe rozwiązanie\n", + "a = np.array([1, 2, 3])\n", + "b = np.array([4, 5, 6])\n", + "print(\"Dodawanie:\", a + b)\n", + "print(\"Mnożenie:\", a * b)\n", + "print(\"Dzielenie:\", a / b)" + ] + }, + { + "cell_type": "markdown", + "id": "92dc2d65", + "metadata": {}, + "source": [ + "## 🎯 Wektoryzacja i broadcasting\n", + "Pokażmy, jak NumPy automatycznie rozszerza kształty macierzy:\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7d8b1810", + "metadata": {}, + "outputs": [], + "source": [ + "a = np.array([1, 2, 3])\n", + "b = 10\n", + "a * b # broadcasting mnożenia przez skalar" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a2a2bb9d", + "metadata": {}, + "outputs": [], + "source": [ + "# Zadanie 3 – Przykładowe rozwiązanie\n", + "macierz = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\n", + "wektor = np.array([10, 20, 30])\n", + "# Dodanie wektora do każdej kolumny\n", + "wynik1 = macierz + wektor\n", + "# Przemnożenie kolumn przez inne wartości\n", + "współczynniki = np.array([1, 2, 3])\n", + "wynik2 = macierz * współczynniki\n", + "print(\"Dodanie:\", wynik1, sep=\"\\n\")\n", + "print(\"Mnożenie:\", wynik2, sep=\"\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4a54d6b7", + "metadata": {}, + "outputs": [], + "source": [ + "# Tutaj wpisz swoje rozwiązanie\n" + ] + }, + { + "cell_type": "markdown", + "id": "1823dd52", + "metadata": {}, + "source": [ + "## ✅ Podsumowanie dnia 1\n", + "Znasz już:\n", + "- podstawy Conda, pip i środowisk\n", + "- jak korzystać z Jupyter Notebook\n", + "- jak tworzyć i przekształcać dane w NumPy\n", + "\n", + "W kolejnym dniu przejdziemy do Pandas i pobierania danych." + ] + } + ], + "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.12.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/PythonAI/readme.md b/PythonAI/readme.md index 64f426a..5f4ef44 100644 --- a/PythonAI/readme.md +++ b/PythonAI/readme.md @@ -27,6 +27,36 @@ Alternatywy: Google Collab, VSCode z rozszerzeniami Python i Jupyter - nie będziemy korzystać bezpośrednio - bo większość szerszych frameworków korzysta z NumPy pod spodem, np Pandas +### Analiza danych w Pythonie +#### Podstawowe pojęcia + - macierze - tablice wierowymiarowe - zawierają elementy tego samego typu + - szeregi - jednowymiarowe tablice. mogą mieć etykiety dla indeksów + - ramki danych - tablice dwuwymiarowe, składają się z kolumn różnych typów + +#### NumPy + - fukcje matematyczne + - trygonometria, geometria, statystyka + - np.random + - maski logiczne, filtrowanie danych + - broadcasting - rozszerzanie małych tablic przy operacjach na większych tablicach + +Statystyka: + - np.mean(), np.median(), np.std(), np.max(), np.min() + +tworzenie tablic: + - np.zeros(), np.ones(), np.arange() + +z NumPy faktycznie się nie korzysta na codzień, bo Pandas to wszystko opakowywuje + +#### Pandas +jest też Polars - nowy, dynamicznie rozwijany, oparty na chmurze, dużo szybszy od Pandas + +Pamdas jest głównie używany do analizy danych, przygotowanie danych do machine learningu + +##### Import danych do Pandas +pd.read_csv(), read_sql(), read_excel() itp itd, bardo dużo formatów + +