Python Pandas indexing, sorting, selecting etc demo.
In this demo, we used Irish Dataset.
print(df['sepal_length'])
print('first items of sepal_length column ')
print(df['sepal_length'][0])
print('all columns of dataframe')
print(df.columns)
print('first row of dataframe')
print(df.iloc[0])
print('second row of dataframe')
print(df.iloc[1])
print('printing all items from sepal_length or 0 index')
print(df.iloc[:, 0])
print('printing all items from sepal_width or 1 index')
print(df.iloc[:, 1])
print('printing 5 items from sepal_length or 0 index')
print(df.iloc[:5, 0])
print('printing all items from sepal_length')
print(df.loc[:,'sepal_length'])
print('printing selected columns')
print(df[['sepal_length', 'sepal_width']])
print('summaries from a column')
print(df['sepal_length'].max())
print(df['sepal_length'].min())
print(df['sepal_length'].mean())
print('conditional selections')
print(df[df['sepal_width'] >4])
print(df['sepal_width'][df['sepal_width'] >4])
print(df[(df['sepal_width'] >3) & (df['sepal_length'] >=6)])
print('sorting dataframe by a column')
print(df.sort_values(by='sepal_length'))
print(df.sort_values(by='sepal_length', ascending=False))