Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views31 pages

Pandas PD Numpy NP Matplotlib - Pyplot PLT Seaborn Sns DF PD - Read - CSV (, Encoding ) DF - Head

Uploaded by

ketan.gawande89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views31 pages

Pandas PD Numpy NP Matplotlib - Pyplot PLT Seaborn Sns DF PD - Read - CSV (, Encoding ) DF - Head

Uploaded by

ketan.gawande89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

# Week 1: (Load, Clean, and Explore Sales Data)

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

#Load the data set


df = pd.read_csv(r'C:\Users\ADITYA\sales.csv', encoding='ISO-8859-1')

# Show the first few rows


df.head()

Row ID Order ID Order Date Ship Date Ship Mode


Customer ID \
0 1 CA-2016-152156 11/8/2016 11/11/2016 Second Class
CG-12520
1 2 CA-2016-152156 11/8/2016 11/11/2016 Second Class
CG-12520
2 4 US-2015-108966 10/11/2015 10/18/2015 Standard Class
SO-20335
3 6 CA-2014-115812 6/9/2014 6/14/2014 Standard Class
BH-11710
4 11 CA-2014-115812 6/9/2014 6/14/2014 Standard Class
BH-11710

Customer Name Segment Country City ...


Postal Code \
0 Claire Gute Consumer United States Henderson ...
42420
1 Claire Gute Consumer United States Henderson ...
42420
2 Sean O'Donnell Consumer United States Fort Lauderdale ...
33311
3 Brosina Hoffman Consumer United States Los Angeles ...
90032
4 Brosina Hoffman Consumer United States Los Angeles ...
90032

Region Product ID Category Sub-Category \


0 South FUR-BO-10001798 Furniture Bookcases
1 South FUR-CH-10000454 Furniture Chairs
2 South FUR-TA-10000577 Furniture Tables
3 West FUR-FU-10001487 Furniture Furnishings
4 West FUR-TA-10001539 Furniture Tables

Product Name Sales


Quantity \
0 Bush Somerset Collection Bookcase 261.9600
2
1 Hon Deluxe Fabric Upholstered Stacking Chairs,... 731.9400
3
2 Bretford CR4500 Series Slim Rectangular Table 957.5775
5
3 Eldon Expressions Wood and Plastic Desk Access... 48.8600
7
4 Chromcraft Rectangular Conference Tables 1706.1840
9

Discount Profit
0 0.00 41.9136
1 0.00 219.5820
2 0.45 -383.0310
3 0.00 14.1694
4 0.20 85.3092

[5 rows x 21 columns]

# Check for null values


df.isnull().sum()

Row ID 0
Order ID 0
Order Date 0
Ship Date 0
Ship Mode 0
Customer ID 0
Customer Name 0
Segment 0
Country 0
City 0
State 0
Postal Code 0
Region 0
Product ID 0
Category 0
Sub-Category 0
Product Name 0
Sales 0
Quantity 0
Discount 0
Profit 0
dtype: int64

df.dropna(inplace=True)

# ----- FEATURE ENGINEERING -----

# 1. Convert 'Order Date' to datetime format


df['Order Date'] = pd.to_datetime(df['Order Date'], errors='coerce')
# 2. Extract Month and Day of Week from Order Date
df['Order Month'] = df['Order Date'].dt.month
df['Order Day'] = df['Order Date'].dt.dayofweek # 0 = Monday, 6 =
Sunday

# 3. Calculate Sales per Item


df['Sales per Item'] = df['Sales'] / df['Quantity']

# 4. Create Profit Margin


df['Profit Margin'] = df['Profit'] / df['Sales']

# 5. Flag high-discount sales (Discount > 30%)


df['High Discount'] = df['Discount'].apply(lambda x: 1 if x > 0.3 else
0)

# Find duplicates
df.duplicated().sum()

# Drop duplicates
df.drop_duplicates(inplace=True)

df.dtypes

Row ID int64
Order ID object
Order Date object
Ship Date object
Ship Mode object
Customer ID object
Customer Name object
Segment object
Country object
City object
State object
Postal Code int64
Region object
Product ID object
Category object
Sub-Category object
Product Name object
Sales float64
Quantity int64
Discount float64
Profit float64
dtype: object

df.describe()

Row ID Postal Code Sales Quantity


Discount \
count 2121.000000 2121.000000 2121.000000 2121.000000
2121.000000
mean 5041.643564 55726.556341 349.834887 3.785007
0.173923
std 2885.740258 32261.888225 503.179145 2.251620
0.181547
min 1.000000 1040.000000 1.892000 1.000000
0.000000
25% 2568.000000 22801.000000 47.040000 2.000000
0.000000
50% 5145.000000 60505.000000 182.220000 3.000000
0.200000
75% 7534.000000 90032.000000 435.168000 5.000000
0.300000
max 9991.000000 99301.000000 4416.174000 14.000000
0.700000

Profit
count 2121.000000
mean 8.699327
std 136.049246
min -1862.312400
25% -12.849000
50% 7.774800
75% 33.726600
max 1013.127000

# Preview the data


df.head()

# Dataset info
df.info()

# Summary statistics for numeric columns


df.describe()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2121 entries, 0 to 2120
Data columns (total 21 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Row ID 2121 non-null int64
1 Order ID 2121 non-null object
2 Order Date 2121 non-null object
3 Ship Date 2121 non-null object
4 Ship Mode 2121 non-null object
5 Customer ID 2121 non-null object
6 Customer Name 2121 non-null object
7 Segment 2121 non-null object
8 Country 2121 non-null object
9 City 2121 non-null object
10 State 2121 non-null object
11 Postal Code 2121 non-null int64
12 Region 2121 non-null object
13 Product ID 2121 non-null object
14 Category 2121 non-null object
15 Sub-Category 2121 non-null object
16 Product Name 2121 non-null object
17 Sales 2121 non-null float64
18 Quantity 2121 non-null int64
19 Discount 2121 non-null float64
20 Profit 2121 non-null float64
dtypes: float64(3), int64(3), object(15)
memory usage: 348.1+ KB

Row ID Postal Code Sales Quantity


Discount \
count 2121.000000 2121.000000 2121.000000 2121.000000
2121.000000
mean 5041.643564 55726.556341 349.834887 3.785007
0.173923
std 2885.740258 32261.888225 503.179145 2.251620
0.181547
min 1.000000 1040.000000 1.892000 1.000000
0.000000
25% 2568.000000 22801.000000 47.040000 2.000000
0.000000
50% 5145.000000 60505.000000 182.220000 3.000000
0.200000
75% 7534.000000 90032.000000 435.168000 5.000000
0.300000
max 9991.000000 99301.000000 4416.174000 14.000000
0.700000

Profit
count 2121.000000
mean 8.699327
std 136.049246
min -1862.312400
25% -12.849000
50% 7.774800
75% 33.726600
max 1013.127000

# Total missing values per column


df.isnull().sum()

# Visualize missing values (optional, using seaborn)


import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(10, 6))
sns.heatmap(df.isnull(), cbar=False, cmap='viridis')
plt.title("Missing Value Heatmap")
plt.show()

# Distribution of a numerical column, e.g. "Sales"


sns.histplot(df['Sales'], kde=True)
plt.title("Distribution of Sales")
plt.show()
# Calculate correlation matrix
corr = df.corr(numeric_only=True)

# Plot heatmap
plt.figure(figsize=(10, 8))
sns.heatmap(corr, annot=True, cmap='coolwarm', fmt=".2f",
linewidths=0.5)
plt.title("Correlation Heatmap")
plt.show()
sns.pairplot(df.select_dtypes(include=['float64', 'int64']))
plt.show()
# For each categorical column, show value counts
for col in df.select_dtypes(include='object').columns:
print(f"\nColumn: {col}")
print(df[col].value_counts())

Column: Order ID
Order ID
US-2017-162558 4
CA-2016-157749 4
US-2015-138121 4
US-2015-129007 4
CA-2014-145387 4
..
CA-2015-122973 1
CA-2016-136322 1
CA-2017-107209 1
CA-2015-162201 1
CA-2017-121258 1
Name: count, Length: 1764, dtype: int64

Column: Order Date


Order Date
9/5/2016 10
11/19/2017 9
10/30/2017 9
12/1/2016 9
12/25/2016 9
..
1/2/2015 1
10/10/2017 1
4/25/2017 1
5/13/2017 1
8/22/2016 1
Name: count, Length: 889, dtype: int64

Column: Ship Date


Ship Date
12/16/2015 10
12/6/2017 10
10/24/2017 9
9/22/2016 8
9/6/2017 8
..
5/16/2015 1
8/10/2015 1
10/19/2014 1
3/31/2014 1
6/27/2017 1
Name: count, Length: 960, dtype: int64

Column: Ship Mode


Ship Mode
Standard Class 1248
Second Class 427
First Class 327
Same Day 119
Name: count, dtype: int64

Column: Customer ID
Customer ID
SV-20365 15
LC-16885 9
KL-16555 9
CJ-12010 9
JE-15745 9
..
BD-11635 1
CS-12130 1
BG-11035 1
SC-20845 1
IM-15055 1
Name: count, Length: 707, dtype: int64

Column: Customer Name


Customer Name
Seth Vernon 15
Lena Creighton 9
Kelly Lampkin 9
Caroline Jumper 9
Joel Eaton 9
..
Brian Derr 1
Chad Sievert 1
Barry Gonzalez 1
Sung Chung 1
Ionia McGrath 1
Name: count, Length: 707, dtype: int64

Column: Segment
Segment
Consumer 1113
Corporate 646
Home Office 362
Name: count, dtype: int64

Column: Country
Country
United States 2121
Name: count, dtype: int64

Column: City
City
New York City 192
Los Angeles 154
Philadelphia 111
San Francisco 102
Seattle 97
...
Mason 1
Santa Barbara 1
Bryan 1
San Bernardino 1
Indianapolis 1
Name: count, Length: 371, dtype: int64

Column: State
State
California 444
New York 236
Texas 202
Pennsylvania 125
Illinois 123
Washington 114
Ohio 93
Florida 85
Virginia 52
Colorado 51
Michigan 50
Arizona 49
Tennessee 45
North Carolina 42
Massachusetts 33
Georgia 32
Wisconsin 32
Kentucky 30
Maryland 28
New Jersey 26
Indiana 23
Oregon 21
Delaware 18
Rhode Island 16
Oklahoma 15
Connecticut 13
Minnesota 13
Missouri 11
Louisiana 11
Alabama 11
Arkansas 9
Mississippi 9
Nevada 9
Utah 7
South Carolina 6
New Hampshire 6
Idaho 6
New Mexico 4
Iowa 4
Nebraska 4
District of Columbia 3
Kansas 2
South Dakota 2
Vermont 2
Maine 1
Wyoming 1
Montana 1
West Virginia 1
Name: count, dtype: int64

Column: Region
Region
West 707
East 601
Central 481
South 332
Name: count, dtype: int64

Column: Product ID
Product ID
FUR-FU-10004270 16
FUR-CH-10001146 15
FUR-CH-10002647 15
FUR-FU-10001473 14
FUR-CH-10003774 14
..
FUR-BO-10000112 1
FUR-FU-10002874 1
FUR-FU-10003095 1
FUR-BO-10001567 1
FUR-CH-10002317 1
Name: count, Length: 375, dtype: int64

Column: Category
Category
Furniture 2121
Name: count, dtype: int64

Column: Sub-Category
Sub-Category
Furnishings 957
Chairs 617
Tables 319
Bookcases 228
Name: count, dtype: int64

Column: Product Name


Product Name
KI Adjustable-Height Table
18
Staple-based wall hangings
16
Situations Contoured Folding Chairs, 4/Set
15
Global Wood Trimmed Manager's Task Chair, Khaki
14
Eldon Wave Desk Accessories
14

..
Bush Birmingham Collection Bookcase, Dark Cherry
1
Ultra Commercial Grade Dual Valve Door Closer
1
Linden 12" Wall Clock With Oak Frame
1
Bush Westfield Collection Bookcases, Dark Cherry Finish, Fully
Assembled 1
Global Enterprise Series Seating Low-Back Swivel/Tilt Chairs
1
Name: count, Length: 380, dtype: int64

print(df.columns)

Index(['Row ID', 'Order ID', 'Order Date', 'Ship Date', 'Ship Mode',
'Customer ID', 'Customer Name', 'Segment', 'Country', 'City',
'State',
'Postal Code', 'Region', 'Product ID', 'Category', 'Sub-
Category',
'Product Name', 'Sales', 'Quantity', 'Discount', 'Profit'],
dtype='object')

grouped = df.groupby(['Order Date', 'Region'])


['Sales'].sum().reset_index()

import matplotlib.pyplot as plt

# Convert to datetime if not already


df['Order Date'] = pd.to_datetime(df['Order Date'])

# Group and sum


grouped = df.groupby(['Order Date', 'Region'])
['Sales'].sum().reset_index()

# Plot for each region


regions = grouped['Region'].unique()

plt.figure(figsize=(12, 6))

for region in regions:


region_data = grouped[grouped['Region'] == region]
plt.plot(region_data['Order Date'], region_data['Sales'],
label=region)

plt.xlabel('Date')
plt.ylabel('Sales')
plt.title('Sales Over Time by Region')
plt.legend()
plt.tight_layout()
plt.show()

# Week 2: (Time Series Analysis by Region)

pivot_df = grouped.pivot(index='Order Date', columns='Region',


values='Sales')

import matplotlib.pyplot as plt

plt.figure(figsize=(14, 6))
pivot_df.plot()
plt.title("Sales Time Series by Region")
plt.xlabel("Date")
plt.ylabel("Sales")
plt.legend(title="Region")
plt.grid(True)
plt.tight_layout()
plt.show()

<Figure size 1400x600 with 0 Axes>


import matplotlib.pyplot as plt

# Example: Central Region


central_ts = pivot_df['Central']

# 30-day rolling average


rolling_avg = central_ts.rolling(window=30).mean()

plt.figure(figsize=(12, 5))
plt.plot(central_ts, label='Original')
plt.plot(rolling_avg, label='30-day Rolling Mean', color='red')
plt.title('Sales Trend - Central Region')
plt.legend()
plt.show()
!pip install statsmodels

Collecting statsmodels
Downloading statsmodels-0.14.5-cp313-cp313-win_amd64.whl.metadata
(9.8 kB)
Requirement already satisfied: numpy<3,>=1.22.3 in c:\users\aditya\
appdata\local\programs\python\python313\lib\site-packages (from
statsmodels) (2.3.1)
Requirement already satisfied: scipy!=1.9.2,>=1.8 in c:\users\aditya\
appdata\local\programs\python\python313\lib\site-packages (from
statsmodels) (1.16.0)
Requirement already satisfied: pandas!=2.1.0,>=1.4 in c:\users\aditya\
appdata\local\programs\python\python313\lib\site-packages (from
statsmodels) (2.3.0)
Collecting patsy>=0.5.6 (from statsmodels)
Downloading patsy-1.0.1-py2.py3-none-any.whl.metadata (3.3 kB)
Requirement already satisfied: packaging>=21.3 in c:\users\aditya\
appdata\local\programs\python\python313\lib\site-packages (from
statsmodels) (25.0)
Requirement already satisfied: python-dateutil>=2.8.2 in c:\users\
aditya\appdata\local\programs\python\python313\lib\site-packages (from
pandas!=2.1.0,>=1.4->statsmodels) (2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in c:\users\aditya\
appdata\local\programs\python\python313\lib\site-packages (from
pandas!=2.1.0,>=1.4->statsmodels) (2025.2)
Requirement already satisfied: tzdata>=2022.7 in c:\users\aditya\
appdata\local\programs\python\python313\lib\site-packages (from
pandas!=2.1.0,>=1.4->statsmodels) (2025.2)
Requirement already satisfied: six>=1.5 in c:\users\aditya\appdata\
local\programs\python\python313\lib\site-packages (from python-
dateutil>=2.8.2->pandas!=2.1.0,>=1.4->statsmodels) (1.17.0)
Downloading statsmodels-0.14.5-cp313-cp313-win_amd64.whl (9.6 MB)
---------------------------------------- 0.0/9.6 MB ? eta -:--:--
---------------------------------------- 0.0/9.6 MB ? eta -:--:--
---------------------------------------- 0.0/9.6 MB ? eta -:--:--
---------------------------------------- 0.0/9.6 MB ? eta -:--:--
---------------------------------------- 0.0/9.6 MB ? eta -:--:--
- -------------------------------------- 0.3/9.6 MB ? eta -:--:--
- -------------------------------------- 0.3/9.6 MB ? eta -:--:--
- -------------------------------------- 0.3/9.6 MB ? eta -:--:--
- -------------------------------------- 0.3/9.6 MB ? eta -:--:--
- -------------------------------------- 0.3/9.6 MB ? eta -:--:--
- -------------------------------------- 0.3/9.6 MB ? eta -:--:--
- -------------------------------------- 0.3/9.6 MB ? eta -:--:--
-- ------------------------------------- 0.5/9.6 MB 172.9 kB/s eta
0:00:53
-- ------------------------------------- 0.5/9.6 MB 172.9 kB/s eta
0:00:53
-- ------------------------------------- 0.5/9.6 MB 172.9 kB/s eta
0:00:53
-- ------------------------------------- 0.5/9.6 MB 172.9 kB/s eta
0:00:53
-- ------------------------------------- 0.5/9.6 MB 172.9 kB/s eta
0:00:53
-- ------------------------------------- 0.5/9.6 MB 172.9 kB/s eta
0:00:53
--- ------------------------------------ 0.8/9.6 MB 194.6 kB/s eta
0:00:46
--- ------------------------------------ 0.8/9.6 MB 194.6 kB/s eta
0:00:46
--- ------------------------------------ 0.8/9.6 MB 194.6 kB/s eta
0:00:46
--- ------------------------------------ 0.8/9.6 MB 194.6 kB/s eta
0:00:46
--- ------------------------------------ 0.8/9.6 MB 194.6 kB/s eta
0:00:46
---- ----------------------------------- 1.0/9.6 MB 206.3 kB/s eta
0:00:42
---- ----------------------------------- 1.0/9.6 MB 206.3 kB/s eta
0:00:42
---- ----------------------------------- 1.0/9.6 MB 206.3 kB/s eta
0:00:42
---- ----------------------------------- 1.0/9.6 MB 206.3 kB/s eta
0:00:42
---- ----------------------------------- 1.0/9.6 MB 206.3 kB/s eta
0:00:42
---- ----------------------------------- 1.0/9.6 MB 206.3 kB/s eta
0:00:42
---- ----------------------------------- 1.0/9.6 MB 206.3 kB/s eta
0:00:42
----- ---------------------------------- 1.3/9.6 MB 196.9 kB/s eta
0:00:43
----- ---------------------------------- 1.3/9.6 MB 196.9 kB/s eta
0:00:43
----- ---------------------------------- 1.3/9.6 MB 196.9 kB/s eta
0:00:43
----- ---------------------------------- 1.3/9.6 MB 196.9 kB/s eta
0:00:43
----- ---------------------------------- 1.3/9.6 MB 196.9 kB/s eta
0:00:43
----- ---------------------------------- 1.3/9.6 MB 196.9 kB/s eta
0:00:43
----- ---------------------------------- 1.3/9.6 MB 196.9 kB/s eta
0:00:43
----- ---------------------------------- 1.3/9.6 MB 196.9 kB/s eta
0:00:43
------ --------------------------------- 1.6/9.6 MB 190.4 kB/s eta
0:00:43
------ --------------------------------- 1.6/9.6 MB 190.4 kB/s eta
0:00:43
------ --------------------------------- 1.6/9.6 MB 190.4 kB/s eta
0:00:43
------ --------------------------------- 1.6/9.6 MB 190.4 kB/s eta
0:00:43
------ --------------------------------- 1.6/9.6 MB 190.4 kB/s eta
0:00:43
------ --------------------------------- 1.6/9.6 MB 190.4 kB/s eta
0:00:43
------ --------------------------------- 1.6/9.6 MB 190.4 kB/s eta
0:00:43
------- -------------------------------- 1.8/9.6 MB 188.5 kB/s eta
0:00:42
------- -------------------------------- 1.8/9.6 MB 188.5 kB/s eta
0:00:42
------- -------------------------------- 1.8/9.6 MB 188.5 kB/s eta
0:00:42
------- -------------------------------- 1.8/9.6 MB 188.5 kB/s eta
0:00:42
------- -------------------------------- 1.8/9.6 MB 188.5 kB/s eta
0:00:42
------- -------------------------------- 1.8/9.6 MB 188.5 kB/s eta
0:00:42
------- -------------------------------- 1.8/9.6 MB 188.5 kB/s eta
0:00:42
------- -------------------------------- 1.8/9.6 MB 188.5 kB/s eta
0:00:42
------- -------------------------------- 1.8/9.6 MB 188.5 kB/s eta
0:00:42
------- -------------------------------- 1.8/9.6 MB 188.5 kB/s eta
0:00:42
-------- ------------------------------- 2.1/9.6 MB 172.8 kB/s eta
0:00:44
-------- ------------------------------- 2.1/9.6 MB 172.8 kB/s eta
0:00:44
-------- ------------------------------- 2.1/9.6 MB 172.8 kB/s eta
0:00:44
-------- ------------------------------- 2.1/9.6 MB 172.8 kB/s eta
0:00:44
-------- ------------------------------- 2.1/9.6 MB 172.8 kB/s eta
0:00:44
-------- ------------------------------- 2.1/9.6 MB 172.8 kB/s eta
0:00:44
-------- ------------------------------- 2.1/9.6 MB 172.8 kB/s eta
0:00:44
-------- ------------------------------- 2.1/9.6 MB 172.8 kB/s eta
0:00:44
-------- ------------------------------- 2.1/9.6 MB 172.8 kB/s eta
0:00:44
-------- ------------------------------- 2.1/9.6 MB 172.8 kB/s eta
0:00:44
-------- ------------------------------- 2.1/9.6 MB 172.8 kB/s eta
0:00:44
-------- ------------------------------- 2.1/9.6 MB 172.8 kB/s eta
0:00:44
--------- ------------------------------ 2.4/9.6 MB 160.9 kB/s eta
0:00:46
--------- ------------------------------ 2.4/9.6 MB 160.9 kB/s eta
0:00:46
--------- ------------------------------ 2.4/9.6 MB 160.9 kB/s eta
0:00:46
--------- ------------------------------ 2.4/9.6 MB 160.9 kB/s eta
0:00:46
--------- ------------------------------ 2.4/9.6 MB 160.9 kB/s eta
0:00:46
--------- ------------------------------ 2.4/9.6 MB 160.9 kB/s eta
0:00:46
--------- ------------------------------ 2.4/9.6 MB 160.9 kB/s eta
0:00:46
--------- ------------------------------ 2.4/9.6 MB 160.9 kB/s eta
0:00:46
---------- ----------------------------- 2.6/9.6 MB 158.5 kB/s eta
0:00:45
---------- ----------------------------- 2.6/9.6 MB 158.5 kB/s eta
0:00:45
---------- ----------------------------- 2.6/9.6 MB 158.5 kB/s eta
0:00:45
---------- ----------------------------- 2.6/9.6 MB 158.5 kB/s eta
0:00:45
---------- ----------------------------- 2.6/9.6 MB 158.5 kB/s eta
0:00:45
---------- ----------------------------- 2.6/9.6 MB 158.5 kB/s eta
0:00:45
------------ --------------------------- 2.9/9.6 MB 163.6 kB/s eta
0:00:42
------------ --------------------------- 2.9/9.6 MB 163.6 kB/s eta
0:00:42
------------ --------------------------- 2.9/9.6 MB 163.6 kB/s eta
0:00:42
------------ --------------------------- 2.9/9.6 MB 163.6 kB/s eta
0:00:42
------------ --------------------------- 2.9/9.6 MB 163.6 kB/s eta
0:00:42
------------ --------------------------- 2.9/9.6 MB 163.6 kB/s eta
0:00:42
------------ --------------------------- 2.9/9.6 MB 163.6 kB/s eta
0:00:42
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
------------- -------------------------- 3.1/9.6 MB 164.4 kB/s eta
0:00:40
-------------- ------------------------- 3.4/9.6 MB 147.3 kB/s eta
0:00:43
-------------- ------------------------- 3.4/9.6 MB 147.3 kB/s eta
0:00:43
-------------- ------------------------- 3.4/9.6 MB 147.3 kB/s eta
0:00:43
-------------- ------------------------- 3.4/9.6 MB 147.3 kB/s eta
0:00:43
-------------- ------------------------- 3.4/9.6 MB 147.3 kB/s eta
0:00:43
-------------- ------------------------- 3.4/9.6 MB 147.3 kB/s eta
0:00:43
-------------- ------------------------- 3.4/9.6 MB 147.3 kB/s eta
0:00:43
--------------- ------------------------ 3.7/9.6 MB 148.6 kB/s eta
0:00:40
--------------- ------------------------ 3.7/9.6 MB 148.6 kB/s eta
0:00:40
--------------- ------------------------ 3.7/9.6 MB 148.6 kB/s eta
0:00:40
--------------- ------------------------ 3.7/9.6 MB 148.6 kB/s eta
0:00:40
--------------- ------------------------ 3.7/9.6 MB 148.6 kB/s eta
0:00:40
--------------- ------------------------ 3.7/9.6 MB 148.6 kB/s eta
0:00:40
--------------- ------------------------ 3.7/9.6 MB 148.6 kB/s eta
0:00:40
---------------- ----------------------- 3.9/9.6 MB 150.5 kB/s eta
0:00:38
---------------- ----------------------- 3.9/9.6 MB 150.5 kB/s eta
0:00:38
---------------- ----------------------- 3.9/9.6 MB 150.5 kB/s eta
0:00:38
---------------- ----------------------- 3.9/9.6 MB 150.5 kB/s eta
0:00:38
---------------- ----------------------- 3.9/9.6 MB 150.5 kB/s eta
0:00:38
---------------- ----------------------- 3.9/9.6 MB 150.5 kB/s eta
0:00:38
---------------- ----------------------- 3.9/9.6 MB 150.5 kB/s eta
0:00:38
---------------- ----------------------- 3.9/9.6 MB 150.5 kB/s eta
0:00:38
---------------- ----------------------- 3.9/9.6 MB 150.5 kB/s eta
0:00:38
----------------- ---------------------- 4.2/9.6 MB 149.6 kB/s eta
0:00:37
----------------- ---------------------- 4.2/9.6 MB 149.6 kB/s eta
0:00:37
----------------- ---------------------- 4.2/9.6 MB 149.6 kB/s eta
0:00:37
----------------- ---------------------- 4.2/9.6 MB 149.6 kB/s eta
0:00:37
----------------- ---------------------- 4.2/9.6 MB 149.6 kB/s eta
0:00:37
----------------- ---------------------- 4.2/9.6 MB 149.6 kB/s eta
0:00:37
----------------- ---------------------- 4.2/9.6 MB 149.6 kB/s eta
0:00:37
------------------ --------------------- 4.5/9.6 MB 151.1 kB/s eta
0:00:35
------------------ --------------------- 4.5/9.6 MB 151.1 kB/s eta
0:00:35
------------------ --------------------- 4.5/9.6 MB 151.1 kB/s eta
0:00:35
------------------ --------------------- 4.5/9.6 MB 151.1 kB/s eta
0:00:35
------------------ --------------------- 4.5/9.6 MB 151.1 kB/s eta
0:00:35
------------------ --------------------- 4.5/9.6 MB 151.1 kB/s eta
0:00:35
------------------ --------------------- 4.5/9.6 MB 151.1 kB/s eta
0:00:35
------------------ --------------------- 4.5/9.6 MB 151.1 kB/s eta
0:00:35
------------------ --------------------- 4.5/9.6 MB 151.1 kB/s eta
0:00:35
------------------ --------------------- 4.5/9.6 MB 151.1 kB/s eta
0:00:35
------------------- -------------------- 4.7/9.6 MB 149.6 kB/s eta
0:00:33
------------------- -------------------- 4.7/9.6 MB 149.6 kB/s eta
0:00:33
------------------- -------------------- 4.7/9.6 MB 149.6 kB/s eta
0:00:33
------------------- -------------------- 4.7/9.6 MB 149.6 kB/s eta
0:00:33
------------------- -------------------- 4.7/9.6 MB 149.6 kB/s eta
0:00:33
------------------- -------------------- 4.7/9.6 MB 149.6 kB/s eta
0:00:33
------------------- -------------------- 4.7/9.6 MB 149.6 kB/s eta
0:00:33
------------------- -------------------- 4.7/9.6 MB 149.6 kB/s eta
0:00:33
-------------------- ------------------- 5.0/9.6 MB 145.2 kB/s eta
0:00:32
-------------------- ------------------- 5.0/9.6 MB 145.2 kB/s eta
0:00:32
-------------------- ------------------- 5.0/9.6 MB 145.2 kB/s eta
0:00:32
-------------------- ------------------- 5.0/9.6 MB 145.2 kB/s eta
0:00:32
-------------------- ------------------- 5.0/9.6 MB 145.2 kB/s eta
0:00:32
-------------------- ------------------- 5.0/9.6 MB 145.2 kB/s eta
0:00:32
--------------------- ------------------ 5.2/9.6 MB 145.0 kB/s eta
0:00:31
--------------------- ------------------ 5.2/9.6 MB 145.0 kB/s eta
0:00:31
--------------------- ------------------ 5.2/9.6 MB 145.0 kB/s eta
0:00:31
--------------------- ------------------ 5.2/9.6 MB 145.0 kB/s eta
0:00:31
--------------------- ------------------ 5.2/9.6 MB 145.0 kB/s eta
0:00:31
---------------------- ----------------- 5.5/9.6 MB 148.6 kB/s eta
0:00:28
---------------------- ----------------- 5.5/9.6 MB 148.6 kB/s eta
0:00:28
---------------------- ----------------- 5.5/9.6 MB 148.6 kB/s eta
0:00:28
---------------------- ----------------- 5.5/9.6 MB 148.6 kB/s eta
0:00:28
---------------------- ----------------- 5.5/9.6 MB 148.6 kB/s eta
0:00:28
---------------------- ----------------- 5.5/9.6 MB 148.6 kB/s eta
0:00:28
---------------------- ----------------- 5.5/9.6 MB 148.6 kB/s eta
0:00:28
------------------------ --------------- 5.8/9.6 MB 148.8 kB/s eta
0:00:26
------------------------ --------------- 5.8/9.6 MB 148.8 kB/s eta
0:00:26
------------------------ --------------- 5.8/9.6 MB 148.8 kB/s eta
0:00:26
------------------------ --------------- 5.8/9.6 MB 148.8 kB/s eta
0:00:26
------------------------ --------------- 5.8/9.6 MB 148.8 kB/s eta
0:00:26
------------------------ --------------- 5.8/9.6 MB 148.8 kB/s eta
0:00:26
------------------------ --------------- 5.8/9.6 MB 148.8 kB/s eta
0:00:26
------------------------ --------------- 5.8/9.6 MB 148.8 kB/s eta
0:00:26
------------------------ --------------- 5.8/9.6 MB 148.8 kB/s eta
0:00:26
------------------------ --------------- 5.8/9.6 MB 148.8 kB/s eta
0:00:26
------------------------ --------------- 5.8/9.6 MB 148.8 kB/s eta
0:00:26
------------------------- -------------- 6.0/9.6 MB 142.8 kB/s eta
0:00:26
------------------------- -------------- 6.0/9.6 MB 142.8 kB/s eta
0:00:26
------------------------- -------------- 6.0/9.6 MB 142.8 kB/s eta
0:00:26
------------------------- -------------- 6.0/9.6 MB 142.8 kB/s eta
0:00:26
------------------------- -------------- 6.0/9.6 MB 142.8 kB/s eta
0:00:26
------------------------- -------------- 6.0/9.6 MB 142.8 kB/s eta
0:00:26
------------------------- -------------- 6.0/9.6 MB 142.8 kB/s eta
0:00:26
-------------------------- ------------- 6.3/9.6 MB 146.9 kB/s eta
0:00:23
-------------------------- ------------- 6.3/9.6 MB 146.9 kB/s eta
0:00:23
-------------------------- ------------- 6.3/9.6 MB 146.9 kB/s eta
0:00:23
-------------------------- ------------- 6.3/9.6 MB 146.9 kB/s eta
0:00:23
-------------------------- ------------- 6.3/9.6 MB 146.9 kB/s eta
0:00:23
-------------------------- ------------- 6.3/9.6 MB 146.9 kB/s eta
0:00:23
-------------------------- ------------- 6.3/9.6 MB 146.9 kB/s eta
0:00:23
--------------------------- ------------ 6.6/9.6 MB 151.9 kB/s eta
0:00:21
--------------------------- ------------ 6.6/9.6 MB 151.9 kB/s eta
0:00:21
--------------------------- ------------ 6.6/9.6 MB 151.9 kB/s eta
0:00:21
--------------------------- ------------ 6.6/9.6 MB 151.9 kB/s eta
0:00:21
--------------------------- ------------ 6.6/9.6 MB 151.9 kB/s eta
0:00:21
--------------------------- ------------ 6.6/9.6 MB 151.9 kB/s eta
0:00:21
--------------------------- ------------ 6.6/9.6 MB 151.9 kB/s eta
0:00:21
--------------------------- ------------ 6.6/9.6 MB 151.9 kB/s eta
0:00:21
--------------------------- ------------ 6.6/9.6 MB 151.9 kB/s eta
0:00:21
---------------------------- ----------- 6.8/9.6 MB 150.9 kB/s eta
0:00:19
---------------------------- ----------- 6.8/9.6 MB 150.9 kB/s eta
0:00:19
---------------------------- ----------- 6.8/9.6 MB 150.9 kB/s eta
0:00:19
---------------------------- ----------- 6.8/9.6 MB 150.9 kB/s eta
0:00:19
---------------------------- ----------- 6.8/9.6 MB 150.9 kB/s eta
0:00:19
---------------------------- ----------- 6.8/9.6 MB 150.9 kB/s eta
0:00:19
---------------------------- ----------- 6.8/9.6 MB 150.9 kB/s eta
0:00:19
----------------------------- ---------- 7.1/9.6 MB 152.5 kB/s eta
0:00:17
----------------------------- ---------- 7.1/9.6 MB 152.5 kB/s eta
0:00:17
----------------------------- ---------- 7.1/9.6 MB 152.5 kB/s eta
0:00:17
----------------------------- ---------- 7.1/9.6 MB 152.5 kB/s eta
0:00:17
----------------------------- ---------- 7.1/9.6 MB 152.5 kB/s eta
0:00:17
------------------------------ --------- 7.3/9.6 MB 152.8 kB/s eta
0:00:15
------------------------------ --------- 7.3/9.6 MB 152.8 kB/s eta
0:00:15
------------------------------ --------- 7.3/9.6 MB 152.8 kB/s eta
0:00:15
------------------------------ --------- 7.3/9.6 MB 152.8 kB/s eta
0:00:15
------------------------------ --------- 7.3/9.6 MB 152.8 kB/s eta
0:00:15
------------------------------ --------- 7.3/9.6 MB 152.8 kB/s eta
0:00:15
------------------------------- -------- 7.6/9.6 MB 154.7 kB/s eta
0:00:13
------------------------------- -------- 7.6/9.6 MB 154.7 kB/s eta
0:00:13
------------------------------- -------- 7.6/9.6 MB 154.7 kB/s eta
0:00:13
------------------------------- -------- 7.6/9.6 MB 154.7 kB/s eta
0:00:13
-------------------------------- ------- 7.9/9.6 MB 159.3 kB/s eta
0:00:11
-------------------------------- ------- 7.9/9.6 MB 159.3 kB/s eta
0:00:11
-------------------------------- ------- 7.9/9.6 MB 159.3 kB/s eta
0:00:11
--------------------------------- ------ 8.1/9.6 MB 177.0 kB/s eta
0:00:09
--------------------------------- ------ 8.1/9.6 MB 177.0 kB/s eta
0:00:09
--------------------------------- ------ 8.1/9.6 MB 177.0 kB/s eta
0:00:09
--------------------------------- ------ 8.1/9.6 MB 177.0 kB/s eta
0:00:09
---------------------------------- ----- 8.4/9.6 MB 181.4 kB/s eta
0:00:07
---------------------------------- ----- 8.4/9.6 MB 181.4 kB/s eta
0:00:07
---------------------------------- ----- 8.4/9.6 MB 181.4 kB/s eta
0:00:07
---------------------------------- ----- 8.4/9.6 MB 181.4 kB/s eta
0:00:07
---------------------------------- ----- 8.4/9.6 MB 181.4 kB/s eta
0:00:07
---------------------------------- ----- 8.4/9.6 MB 181.4 kB/s eta
0:00:07
------------------------------------ --- 8.7/9.6 MB 182.3 kB/s eta
0:00:06
------------------------------------ --- 8.7/9.6 MB 182.3 kB/s eta
0:00:06
------------------------------------ --- 8.7/9.6 MB 182.3 kB/s eta
0:00:06
------------------------------------ --- 8.7/9.6 MB 182.3 kB/s eta
0:00:06
------------------------------------ --- 8.7/9.6 MB 182.3 kB/s eta
0:00:06
------------------------------------- -- 8.9/9.6 MB 184.6 kB/s eta
0:00:04
------------------------------------- -- 8.9/9.6 MB 184.6 kB/s eta
0:00:04
------------------------------------- -- 8.9/9.6 MB 184.6 kB/s eta
0:00:04
------------------------------------- -- 8.9/9.6 MB 184.6 kB/s eta
0:00:04
------------------------------------- -- 8.9/9.6 MB 184.6 kB/s eta
0:00:04
------------------------------------- -- 8.9/9.6 MB 184.6 kB/s eta
0:00:04
------------------------------------- -- 8.9/9.6 MB 184.6 kB/s eta
0:00:04
------------------------------------- -- 8.9/9.6 MB 184.6 kB/s eta
0:00:04
------------------------------------- -- 8.9/9.6 MB 184.6 kB/s eta
0:00:04
------------------------------------- -- 8.9/9.6 MB 184.6 kB/s eta
0:00:04
------------------------------------- -- 8.9/9.6 MB 184.6 kB/s eta
0:00:04
------------------------------------- -- 8.9/9.6 MB 184.6 kB/s eta
0:00:04
-------------------------------------- - 9.2/9.6 MB 179.1 kB/s eta
0:00:03
-------------------------------------- - 9.2/9.6 MB 179.1 kB/s eta
0:00:03
-------------------------------------- - 9.2/9.6 MB 179.1 kB/s eta
0:00:03
-------------------------------------- - 9.2/9.6 MB 179.1 kB/s eta
0:00:03
-------------------------------------- - 9.2/9.6 MB 179.1 kB/s eta
0:00:03
-------------------------------------- - 9.2/9.6 MB 179.1 kB/s eta
0:00:03
-------------------------------------- - 9.2/9.6 MB 179.1 kB/s eta
0:00:03
-------------------------------------- - 9.2/9.6 MB 179.1 kB/s eta
0:00:03
-------------------------------------- - 9.2/9.6 MB 179.1 kB/s eta
0:00:03
-------------------------------------- - 9.2/9.6 MB 179.1 kB/s eta
0:00:03
--------------------------------------- 9.4/9.6 MB 178.0 kB/s eta
0:00:01
--------------------------------------- 9.4/9.6 MB 178.0 kB/s eta
0:00:01
--------------------------------------- 9.4/9.6 MB 178.0 kB/s eta
0:00:01
---------------------------------------- 9.6/9.6 MB 179.0 kB/s eta
0:00:00
Downloading patsy-1.0.1-py2.py3-none-any.whl (232 kB)
Installing collected packages: patsy, statsmodels
Successfully installed patsy-1.0.1 statsmodels-0.14.5

[notice] A new release of pip is available: 24.3.1 -> 25.1.1


[notice] To update, run: python.exe -m pip install --upgrade pip
from statsmodels.tsa.seasonal import seasonal_decompose

# Drop NaNs if necessary


ts = central_ts.dropna()

# Decompose
decomposition = seasonal_decompose(ts, model='additive', period=30)

# Plot components
decomposition.plot()
plt.tight_layout()
plt.show()

from statsmodels.graphics.tsaplots import plot_acf, plot_pacf

plt.figure(figsize=(12, 5))
plot_acf(ts, lags=40)
plt.title('Autocorrelation (ACF) - Central Region')
plt.show()

plt.figure(figsize=(12, 5))
plot_pacf(ts, lags=40, method='ywm') # or method='ld'
plt.title('Partial Autocorrelation (PACF) - Central Region')
plt.show()

<Figure size 1200x500 with 0 Axes>

<Figure size 1200x500 with 0 Axes>

You might also like