Module 05.0 - PA - Pandas - DataFrame - Select - Data
Module 05.0 - PA - Pandas - DataFrame - Select - Data
# https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html
# Get records from row number 10 to 14 from the DataFrame. Row 15 is excluded.
df[10:15]
# Get records from row number 0 to 3 from the the tail of the dataframe. Row -3 is
excluded.
df[-3:]
# Get records from row number 0 to 4 from the the head of the dataframe.
df[:-20]
# Get records from row number 1 to 3 from the the tail of the dataframe. Row -3 is
excluded.
df[-5:-1]
# Get the records of row number 10,15,17,20 and columns 'actual_price' and
'discounted_price'
df.loc[[10,15,17,20],['actual_price','discounted_price']]
# Get the records from row number 10 to 15 and columns 'actual_price' and
'discounted_price'
df.loc[10:15,['actual_price','discounted_price']]
# Get records from row number 1 to 15, and columns from 1 to 3 from the DataFrame.
# Row 15 and column 3 are excluded.
df.iloc[1:15,1:3]
# Get records of 3 row from the tail, and columns from 2 to 4 from the DataFrame.
df.iloc[-3:,2:5]
# Get records from row number 3 to 8 from the tail, and columns from 1 to 3 from
the tail.
# 3rd will be considered.
df.iloc[-8:-3,-4:-1]