{ "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 }