Page 81 - IPP-12-2024
P. 81
print(df.shape)
print(df.head())
print("Tail")
print(df.tail(2))
print("Specified Number of Rows")
print(df[2:5])
print("Print Everything")
print(df[:])
print("Print Column Names")
print(df.columns)
print("Data from Individual Column")
print(df['day']) #or df.day
print(df['temperature'])
print("Maximum Temperature : ", df['temperature'].max())
print("Printing According to Condition")
print(df[df.temperature>41])
print("Printing the row with maximum temperature")
print(df[df.temperature==df.temperature.max()])
print("Printing specific columns with maximum temperature")
print(df[['day','temperature']][df.temperature==df.temperature.max()])
print("According to index")
print(df.loc[3])
print("Changing of Index")
df.set_index('day',inplace=True)
print(df)
print("Searching according to new index")
print(df.loc['01/03/2018'])
print("Resetting the Index")
df.reset_index(inplace=True)
print(df)
print("Sorting")
print(df.sort_values(by=['temperature'],ascending=False))
print("Sorting on Multiple Columns")
print(df.sort_values(by=['temperature','windspeed'],ascending=True))
print("Sorting on Multiple Columns one in ascending, another in
descending")
print(df.sort_values(by=['temperature','windspeed'],ascending=[True,Fal
se]))
print("Sum Operations on Data Frame")
print(df['temperature'].sum())
print("Group By Operations")
print(df.groupby('windspeed')['temperature'].sum())
Output:
day temperature windspeed event
0 01/01/2018 42 6 Sunny
1 01/02/2018 41 7 Rain
2 01/03/2018 43 2 Sunny