pandas loc, iloc

PHOTO EMBED

Mon Jan 03 2022 13:36:21 GMT+0000 (Coordinated Universal Time)

Saved by @ahoeweler

# loc --> label-based
# iloc --> integer position-based
# both are more versatile than brackes []

# get specific row/col interception of data frame
data.loc[['row1', 'row2'], ['col1', 'col2']]

# iloc using indeces
data.iloc[[1,2], [1,2]] --> same result

# iloc for just rows (e.g. first 5 rows --> [:5])
df.iloc[a:b]

# iloc for just columns (e.g. columns 3-4)
df.iloc[:, 2:4]

# select column and create series
data_csv.loc[:, 'col1']

# select column and create dataframe
data_csv.loc[:, ['col1']]
content_copyCOPY