0

I am trying to calculate sum of column_name "Email" and trying to groupby column_name "country". The error is in converting str to int

Script:

df3 = pd.read_csv('hi.csv',sep = ',')
df3['h1'] = df3['h1'].astype(int)
new_df3=df3.groupby(['country']).h1.sum().to_frame('count').reset_index()
print(new_df3)

Input:

cou h1
A   hi
C   watsup
G   hi

1 Answers1

1

try this

df3.groupby('country')['Email1'].count()

there is no need to convert email to int just counting emails should do the work.

Tserenjamts
  • 579
  • 6
  • 15
  • getting error : can only concatenate str (not "int") to str During handling of the above exception, another exception occurred: –  Nov 11 '19 at 04:35