0% found this document useful (0 votes)
3 views

Infinitycliff Python

This document is a Python cheat sheet focused on using the pandas library for data manipulation. It includes examples for creating DataFrames, reading and writing data in various formats, and performing operations such as merging, sorting, and extracting values. The cheat sheet serves as a quick reference for common pandas functions and their usage.

Uploaded by

gabrielzurt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Infinitycliff Python

This document is a Python cheat sheet focused on using the pandas library for data manipulation. It includes examples for creating DataFrames, reading and writing data in various formats, and performing operations such as merging, sorting, and extracting values. The cheat sheet serves as a quick reference for common pandas functions and their usage.

Uploaded by

gabrielzurt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Python Cheat Sheet

by InfinityCliff via cheatography.com/79806/cs/19308/

Creating a Dataframe (copy) pandas Functions Reading and writing data

df = pd.Dat​aFr​‐ Empty len(df) Number of rows in DataFrame Excel


ame() DataFrame df.dtypes Data type of each column df = pd.rea​​d_​exc​el(​​'​fil​​e.x​‐
df.columns DataFrame column list of lsx', sheet_​name= 'sheet name)
Pandas DataFrame [...]
names str
Merge [...] df.count() Number of values in each
df.to_excel('file.xlsx',

df = pd.mer​ge(​lef​t=l​eft_df, column sheet_​nam​e='​sheet name' [...]

right=​rig​ht_df, on='FI​ELD', df.sum() Sum of values in each column Excel multi sheets
valida​te=​'m:m')
df.min() Minimum value in each with pd.Exc​elW​rit​er(​'pa​th_​to_​‐
Select Rows based on column value column fil​e.x​lsx') as writer:

df.lo​c[d​f['​col​umn​_name'] == df.max() Maximum value in each df1.to​_ex​cel​(wr​iter, sheet_​‐

some_v​alue] column nam​e='​She​et1')


df2.to​_ex​cel​(wr​iter, sheet_​‐
df[(d​f.f​ield1 cond1) & df.mean() Mean value in each column
(df.field2 cond2)] nam​e='​She​et2')
Replace df with df["​​Column Name"] or an
Sort (by specified Field) equivalent variable to use these functions pickle

df.so​rt_​val​ues​('F​IELD') for a single column or set of selected df =


values. pd.read_pickle('file.pickle')
Fill a column with value
[...]
df['A'] = 'foo' df.to​_pi​ckl​e('​fil​e.p​ick​le') [...]
Reset Index csv
df.re​set​_in​dex​(in​pla​ce=​True) df = pd.rea​​d_​c​s​v('​​fi​l​e.c​​sv')
Extract [month, date, hour, etc] from [...]
datetime column
[...]
df['N​EW_​FIELD'] = df['dt​_FI​‐
ELD​'].d​t.<​va​lue​> value=​month, Class Property Ddecor​ators
date, hour
@property
Set Index def val(self):
df.se​t_i​nde​x(keys, drop=True, ​ ​ ​ ​return self._val
append​=False, inplac​e=F​alse, @val.s​etter
verify​_in​teg​rit​y=F​alse) def temper​atu​re(​self, value):
​ ​ ​ ​sel​f._val = value
Docume​nta​tion:
http:/​/pa​nda​s.p​yda​ta.o​rg​/pa​nda​s-d​ocs​/st​‐
able/

[...]

By InfinityCliff Not published yet. Sponsored by ApolloPad.com


cheatography.com/infinitycliff/ Last updated 25th April, 2019. Everyone has a novel in them. Finish
Page 1 of 1. Yours!
https://apollopad.com

You might also like