Python With Excel and Text Strings
Pandas Dataframes
Let’s now get the bottom few row from a dataframe
Code:
import pandas as pd
df = pd.read_excel('europe_cities_by_sunshine.xlsx')
df = df.sort_values('Year', ascending=False)
df.tail(5)
Explanation:
It’s a simple change to get the last few rows of a dataframe — use the df.tail() function and pass in how many rows you want returned. Notice how the data makes sense too since the last few rows will have the least amount of sunshine, so this group will not include Cyprus, Spain, or Greece but rather the UK and Norway.