I have a few dataframes that look like this that follow the same format.
this is df1:
country ticker
0 US MSFT
1 US AAPL
2 GERMANY NSU.DE
3 SG D05.SI
4 AUS WOW.AX
this is df2:
country ticker
0 HK 0700.HK
1 HK 1337.HK
2 SWISS NESN.SW
3 SG OV8.SI
The dataframes are saved into csv files with multiple sheets. I can cycle over them easily.
I want to create a frame or dictionary or variables that counts the total times the countries appear like this.
country count
0 US 2
1 GERMANY 1
2 SG 2
3 AUS 1
4 SWISS 1
5 HK 2
How can I do that? It doesnt have to be a dataframe.
a = dict(df['country'].value_counts(dropna=False)), should give you a dict obj like{"US": 2, ...}, you can loop across your sheets and update yourdictobject to get all counts.