Professional Documents
Culture Documents
Learn Pandas Dataframe Object Cheat Sheet Part-8
Learn Pandas Dataframe Object Cheat Sheet Part-8
PANDAS
DATAFRAME
OBJECT
CHEAT SHEET PART 8
Follow On www.1stepgrow.com
Select a slice of rows by integer position
[inclusive-from : exclusive-to [: step]]
default start is 0; default end is len(df)
Follow On www.1stepgrow.com
Select a slice of rows by label/index
[inclusive-from : inclusive–to [ : step]]
Follow On www.1stepgrow.com
Iterating over DataFrame rows
df = df.sort(df.columns[0],
ascending=False)
df.sort(['col1', 'col2'], inplace=True)
Follow On www.1stepgrow.com
Random selection of rows
import random as r
k = 20 # pick a number
selection = r.sample(range(len(df)), k)
df_sample = df.iloc[selection, :]
Follow On www.1stepgrow.com
Drop duplicates in the row index
Follow On www.1stepgrow.com
Get the integer position of a row or col index label
i = df.index.get_loc('row_label')
Follow On www.1stepgrow.com
IS THIS
INFORMATIO
N HELPFULL?
Don't forget to like, share, and save this post if you found
it useful!
Follow On www.1stepgrow.com