We use cookies to understand how the site is used and to display ads. Analytics and advertising only run after you accept. You can change your choice anytime. Privacy policy

Skip to content
devvkit
$devvkit learn --librarie pandas-guide

Pandas Guide

[python][data][analysis]
Python
Install
pip install pandas

Core data structure: DataFrame: a labeled, two-dimensional table with typed columns.

Handles real-world data messiness: NaN, inconsistent formats, duplicates.

Never loop over rows: use vectorized operations with apply(), groupby(), boolean indexing.

Creating DataFrames

Create DF· From dictionary.
import pandas as pd
df = pd.DataFrame({'name': ['Alice', 'Bob'], 'age': [30, 25]})

Reading / Writing

Read CSV· Load CSV file.
df = pd.read_csv('data.csv')
df = pd.read_csv('data.csv', nrows=100)
Write CSV· Save to CSV.
df.to_csv('output.csv', index=False)

Selecting & Filtering

Inspect· View data.
df.head(10)
df.info()
df.describe()
Select columns· Choose columns.
df['name']
df[['name', 'age']]
Filter rows· Condition.
df[df['age'] > 25]
df[(df['age'] > 25) & (df['city'] == 'NYC')]
Query· SQL-like filter.
df.query('age > 25 and city == 'NYC'')

Manipulation

Add column· New column.
df['age_group'] = df['age'].apply(lambda x: 'young' if x < 30 else 'adult')
Merge· Join DataFrames.
pd.merge(df1, df2, on='user_id', how='left')

Grouping & Aggregation

Group by· Aggregate.
df.groupby('city').agg({'age': ['mean', 'count', 'max']})