Python With Excel and Text Strings
Pandas Dataframes
Let’s now use the Count function in a dataframe
Code:
import pandas as pd
df = pd.read_excel('europe_cities_by_sunshine.xlsx')
df = df[['Country', 'Year']]
df = df.groupby(by=["Country"]).count()
Explanation:
Now, we’re calculating the count of each country, so we can see Cyprus is 2 since there are 2 entries for Cyprus in the original Excel dataframe.