0% found this document useful (0 votes)
12 views2 pages

01 Python Data Analysis Cheatsheet

This document is a practical cheatsheet for data analysis using Python's Pandas library, covering essential operations such as loading data, data cleaning, filtering, aggregation, and visualization. It provides code snippets for common tasks like handling missing values, grouping data, and creating plots with Matplotlib. The cheatsheet serves as a quick reference for analysts and engineers to efficiently manipulate and analyze structured data.

Uploaded by

Ghilman Fatih
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)
12 views2 pages

01 Python Data Analysis Cheatsheet

This document is a practical cheatsheet for data analysis using Python's Pandas library, covering essential operations such as loading data, data cleaning, filtering, aggregation, and visualization. It provides code snippets for common tasks like handling missing values, grouping data, and creating plots with Matplotlib. The cheatsheet serves as a quick reference for analysts and engineers to efficiently manipulate and analyze structured data.

Uploaded by

Ghilman Fatih
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

Python Data Analysis

A Practical Cheatsheet for Analysts & Engineers

1. Getting Started with Pandas


Pandas is the cornerstone library for data manipulation in Python. It provides two primary data
structures — Series (1D) and DataFrame (2D) — that make working with structured data
intuitive and efficient. Below are the most commonly used operations that every data analyst
should have at their fingertips.

Loading Data
import pandas as pd
df = pd.read_csv('[Link]') # from CSV
df = pd.read_excel('[Link]') # from Excel
df = pd.read_json('[Link]') # from JSON
df = pd.read_sql(query, connection) # from SQL

Inspection & Summary


[Link](10) # first 10 rows
[Link](5) # last 5 rows
[Link]() # dtypes and nulls
[Link]() # statistical summary
[Link] # (rows, columns)
[Link]() # list of column names
[Link]().sum() # count missing values per column

2. Data Cleaning
Data rarely arrives in a clean, analysis-ready format. The following operations cover the most
common cleaning tasks: handling missing values, removing duplicates, fixing data types, and
renaming columns.

[Link]() # drop rows with any NaN


[Link](0) # fill NaN with 0
[Link]([Link]()) # fill with column mean
df.drop_duplicates() # remove duplicate rows
df['col'] = df['col'].astype(int) # cast dtype
[Link](columns={'old': 'new'}) # rename columns
df['date'] = pd.to_datetime(df['date']) # parse dates

3. Filtering & Selection


df[df['age'] > 30] # filter rows
df[df['city'].isin(['Jakarta', 'Bali'])] # isin filter
[Link][0:5, ['name', 'age']] # loc: label-based
[Link][0:5, 0:3] # iloc: position-based
[Link]('age > 25 and city == "Jakarta"') # query syntax

4. Aggregation & GroupBy


GroupBy is one of the most powerful tools in Pandas. It follows a split-apply-combine pattern:
split data into groups, apply an aggregation, and combine results.

[Link]('category')['sales'].sum()
[Link](['region', 'category']).agg({'sales': 'sum', 'qty': 'mean'})
df.pivot_table(values='sales', index='region', columns='category',
aggfunc='sum')

5. Quick Visualization with Matplotlib


While Pandas has built-in plotting via Matplotlib, knowing the direct Matplotlib API gives more
control.

import [Link] as plt


df['sales'].plot(kind='bar') # bar chart
df['value'].plot(kind='hist', bins=20) # histogram
[Link](x='date', y='sales', kind='line') # line chart
[Link]('[Link]', dpi=150, bbox_inches='tight')

Python Data Analysis Cheatsheet — v1.0 — For educational use

You might also like