POST POST

OCT
22
2021

Pandas Cheat Sheet

ORIGINALLY POSTED TO: https://blog.simontimms.com/2021/10/22/pandas-cheat-sheet

Part of an evolving cheat sheet

Read a file

For CSV use

1
data = pd.read_csv('data.csv')

Get a summary of the data

Numerical summaries

1
data.describe()

Types of columns

1
data.dtypes

Create a new column from combining with another

This adds up values in two columns

1
data["totalqueuelength"] = data["Svc"] + data["Svc Que"]

This converts a couple of columns that have the data and time to a single field and turns it into a date

1
data["datetime"] = pd.to_datetime(data["Date"] + " " + data["Time"], format='%m/%d/%Y %I:%M %p')

Check date formats at https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior

Filter data rows

1
data.loc[(data['datetime'] > '2021-10-16')]

Simon Timms

Email Email
Web Web
Twitter Twitter
GitHub GitHub
RSS

Looking for someone else?

You can find the rest of the Western Devs Crew here.

© 2015 Western Devs. All Rights Reserved. Design by Karen Chudobiak, Graphic Designer