Pandas Functions Worth Memorizing

Find Unique Values in a Column

df["column_name"].unique()

This function allows you to easily see what data you have in a column and what the distribution of that data is.

Web Scraping

pd.read_html("URL")

Webscraping is a key reason that someone might use Python. Pandas has a powerful, yet little known function that allows you to pass in a URL and start handling the tabular data at that address. Here is the full documentation.

Correlation Matrix

df.corr()

Understanding the correlations between your numerical columns is a great first step in deciding what type of analysis you want to apply to the data. Pandas has a function that you can tack on to any dataframe and automatically produces a correlation matrix for the appropriate columns.

Replace Null Values with Zeros (for example)

df.replace(np.nan, "0", inplace = True)

Getting rid of null values can be a key aspect of data cleaning and data analysis, though not all analyses require this step. There many ways of going about this, but this simple, one line function takes all the null values and replaces them with zeros. You can switch out the “0” with anything else by replacing what you put in the quotations.

Export your Dataframe to an Excel File

df.to_excel('dir/myDataFrame.xlsx',  sheet_name='Sheet1')

Understanding how to go back and forth between Excel and Python can be tricky, but many data scientists will find themselves grappling with this workflow frequently. This function allows you to pass your dataframe to an existing Excel file. All you need to do is specify the file path and the sheet name as arguments in the function. Here is the full Pandas to Excel documentation.

Retrieve Dataframe Information

Return the amount of rows and columns in your dataframe:

df.shape()

Get summary statistics about your dataframe:

df.describe()

I hope these functions are helpful :)

--

--

--

Exploring the future of Python and Spreadsheets

Love podcasts or audiobooks? Learn on the go with our new app.

Data-Driven Interview Advice: How the Best Teams Screen Data Scientists

Which majors do TikTok users find most attractive?

Analyzing the Chances of a Stroke in R

Data materialization and digital literacies

False discovery rate, Type-M and Type-S errors in an underpowered A/B test

Write a Data Science Blog Post

Place Your Products with Their Mates: Association Rule Learning

Welcome to the Tableau economy

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jake from Mito

Jake from Mito

Exploring the future of Python and Spreadsheets

More from Medium

3 Ways to Perform Outlier Detection in 3 Lines of Python Code

Dictionaries in Python

Working with SQL in Python Environment ?

Data Analysis project- Using SQL to Clean and Analyse Data.