- Pandas Basics Cheat Sheet Printable
- Panda Warmer Cheat Sheets
- Pandas Basics Cheat Sheet (2021) Python For Data Science
- Pandas Basics Cheat Sheet Pdf
Python basics or Python Debugger cheat sheets for beginners covers important syntax to get started. Community-provided libraries such as numpy, scipy, sci-kit and pandas are highly relied on and the NumPy/SciPy/Pandas Cheat Sheet provides a quick refresher to these. Python 2.7 Quick Reference Sheet; Python Cheat Sheet by DaveChild via. Python Data Visualization Bokeh 2. Enjoy our journey. If you have any suggestion or comments, or any question, please email me. The 26 Best Cheat Sheets & Infographics for Artificial Intelligence, Machine Learning, Deep Learning, Neural Networks & Big Data Science. Pandas Cheat Sheet Python Pandas Cheat Sheet Pandas is one of the most popular packages in Python. It is widely used for data manipulation, data cleaning and wrangling. Panda’s package comes up with multiple feature-rich functions and options which could be overwhelming.
Pandas cheat sheet¶¶
Pandas is Python Data Analysis library. Series and Dataframes are major data structures in Pandas. Pandas is built on top of NumPy arrays.
ToC
- Series
- DataFrames
- Slicing and dicing DataFrames
- Conditional selection
- Operations on DataFrames
- DataFrame index
Series¶¶
Pandas Basics Cheat Sheet Printable
Series is 1 dimensional data structure. It is similar to numpy array, but each data point has a label in the place of an index.
Create a series¶¶
Thus Series can have different datatypes.
Operations on series¶¶
You can add, multiply and other numerical opertions on Series just like on numpy arrays.
When labels dont match, it puts a nan. Thus when two series are added, you may or may not get the same number of elements
DataFrames¶¶
Creating dataFrames¶¶
Pandas DataFrames are built on top of Series. It looks similar to a NumPy array, but has labels for both columns and rows.
reliability | cost | competition | halflife | |
---|---|---|---|---|
Car1 | 0.134302 | 0.625207 | 0.970981 | 0.717605 |
Car2 | 0.713766 | 0.773182 | 0.059689 | 0.450899 |
Car3 | 0.058990 | 0.904301 | 0.431487 | 0.087683 |
Car4 | 0.509891 | 0.501037 | 0.244279 | 0.763135 |
Slicing and dicing DataFrames¶¶
You can access DataFrames similar to Series and slice it similar to NumPy arrays
Access columns¶¶
Accessing using index number¶¶
If you don’t know the labels, but know the index like in an array, use iloc
and pass the index number.
Dicing DataFrames¶¶
Dicing using labels > use DataFrameObj.loc[[row_labels],[col_labels]]
cost | competition | |
---|---|---|
Car2 | 0.935368 | 0.719570 |
Car3 | 0.659950 | 0.605077 |
cost | competition | |
---|---|---|
Car2 | 0.935368 | 0.719570 |
Car3 | 0.659950 | 0.605077 |
Conditional selection¶¶
When running a condition on a DataFrame, you are returned a Bool dataframe.
reliability | cost | competition | halflife | |
---|---|---|---|---|
Car1 | 0.776415 | 0.435083 | 0.236151 | 0.169087 |
Car2 | 0.790403 | 0.987459 | 0.370570 | 0.734146 |
Car3 | 0.884783 | 0.233803 | 0.691639 | 0.725398 |
Car4 | 0.693038 | 0.716824 | 0.766937 | 0.490821 |
reliability | cost | competition | halflife | |
---|---|---|---|---|
Car3 | 0.884783 | 0.233803 | 0.691639 | 0.725398 |
Chaining conditions¶¶
In a Pythonic way, you can chain conditions
Multiple conditions¶¶
You can select dataframe elements with multiple conditions. Note cannot use Python and
, or
. Instead use &
, |
reliability | cost | competition | halflife | |
---|---|---|---|---|
Car1 | 0.776415 | 0.435083 | 0.236151 | 0.169087 |
Car2 | 0.790403 | 0.987459 | 0.370570 | 0.734146 |
reliability | cost | competition | halflife | |
---|---|---|---|---|
Car1 | 0.776415 | 0.435083 | 0.236151 | 0.169087 |
Car2 | 0.790403 | 0.987459 | 0.370570 | 0.734146 |
Car3 | 0.884783 | 0.233803 | 0.691639 | 0.725398 |
Operations on DataFrames¶¶
Adding new columns¶¶
Create new columns just like adding a kvp to a dictionary.
reliability | cost | competition | halflife | full_life | |
---|---|---|---|---|---|
Car1 | 0.134302 | 0.625207 | 0.970981 | 0.717605 | 1.435210 |
Car2 | 0.713766 | 0.773182 | 0.059689 | 0.450899 | 0.901799 |
Car3 | 0.058990 | 0.904301 | 0.431487 | 0.087683 | 0.175366 |
Car4 | 0.509891 | 0.501037 | 0.244279 | 0.763135 | 1.526270 |
Dropping rows and columns¶¶
Row labels are axis = 0
and columns are axis = 1
reliability | cost | competition | halflife | |
---|---|---|---|---|
Car1 | 0.134302 | 0.625207 | 0.970981 | 0.717605 |
Car2 | 0.713766 | 0.773182 | 0.059689 | 0.450899 |
Car3 | 0.058990 | 0.904301 | 0.431487 | 0.087683 |
Car4 | 0.509891 | 0.501037 | 0.244279 | 0.763135 |
reliability | cost | competition | halflife | full_life | |
---|---|---|---|---|---|
Car1 | 0.134302 | 0.625207 | 0.970981 | 0.717605 | 1.435210 |
Car2 | 0.713766 | 0.773182 | 0.059689 | 0.450899 | 0.901799 |
Car4 | 0.509891 | 0.501037 | 0.244279 | 0.763135 | 1.526270 |
reliability | cost | competition | halflife | full_life | |
---|---|---|---|---|---|
Car1 | 0.134302 | 0.625207 | 0.970981 | 0.717605 | 1.43521 |
Car4 | 0.509891 | 0.501037 | 0.244279 | 0.763135 | 1.52627 |
DataFrame Index¶¶
So far, Car1
, Car2
.. is the index for rows. If you would like to set a different column as an index, use set_index
. If you want to make index as a column rather, and use numerals for index, use reset_index
Panda Warmer Cheat Sheets
Set index¶¶
reliability | cost | competition | halflife | car_names | |
---|---|---|---|---|---|
Car1 | 0.776415 | 0.435083 | 0.236151 | 0.169087 | altima |
Car2 | 0.790403 | 0.987459 | 0.370570 | 0.734146 | outback |
Car3 | 0.884783 | 0.233803 | 0.691639 | 0.725398 | taurus |
Car4 | 0.693038 | 0.716824 | 0.766937 | 0.490821 | mustang |
Pandas Basics Cheat Sheet (2021) Python For Data Science
reliability | cost | competition | halflife | car_names | |
---|---|---|---|---|---|
car_names | |||||
altima | 0.776415 | 0.435083 | 0.236151 | 0.169087 | altima |
outback | 0.790403 | 0.987459 | 0.370570 | 0.734146 | outback |
taurus | 0.884783 | 0.233803 | 0.691639 | 0.725398 | taurus |
mustang | 0.693038 | 0.716824 | 0.766937 | 0.490821 | mustang |
Pandas Basics Cheat Sheet Pdf
index | reliability | cost | competition | halflife | car_names | |
---|---|---|---|---|---|---|
0 | Car1 | 0.776415 | 0.435083 | 0.236151 | 0.169087 | altima |
1 | Car2 | 0.790403 | 0.987459 | 0.370570 | 0.734146 | outback |
2 | Car3 | 0.884783 | 0.233803 | 0.691639 | 0.725398 | taurus |
3 | Car4 | 0.693038 | 0.716824 | 0.766937 | 0.490821 | mustang |