Menu

1 / 2

Python Pandas Crash Course: Analyze Data in 20 Minutes

DEV Community·Brad·6 months ago
#azXEjq8N
#python#datascience#pandas#tutorial#date
Reading 0:00
15s threshold

Python Pandas Crash Course: Analyze Data in 20 Minutes

Pandas is the most popular Python library for data analysis. Here's what you need to know.

Load and Inspect Data

import pandas as pd

df = pd . read_csv ( ' sales.csv ' , parse_dates = [ ' date ' ]) print ( df . shape ) # (rows, cols) print ( df . info ()) # Column types, null counts print ( df . describe ()) # Statistical summary print ( df . head ( 5 )) # First 5 rows

Enter fullscreen mode

Exit fullscreen mode

Filter and Select

# Filter rows high_sales = df [ df [ ' revenue ' ] > 1000 ] q4 = df [ df [ ' date ' ]. dt . quarter == 4 ]

# Select columns subset = df [[ ' product ' , ' revenue ' , ' date ' ]]

# Multiple conditions result = df [( df [ ' revenue ' ] > 500 ) & ( df [ ' status ' ] == ' completed ' )]

Enter fullscreen mode

Exit fullscreen mode

Group and Aggregate

# Monthly sales summary monthly = df . groupby ( df [ ' date ' ]. dt . to_period ( ' M ' )).…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.