I´m trying to add a percentage column into a dataframe, but when i try to add it to the new column all i get is NaN values
To create the column 'percent_clicked' on the 'clicks_pivot' df:
clicks_pivot['percent_clicked'] = (clicks_pivot.user_id / clicks_pivot.user_id.sum()) * 100
Printing the modified 'clicks_pivot' i get:
utm_source
email 255 NaN
facebook504 NaN
google 680 NaN
twitter 215 NaN
How can i get the % instead of the NaN values?
CodePudding user response:
it works, i tested. Before using the code make sure the column in question is not holding strings instead of ints.
df['b'] = (df['a'] / df['a'].sum()) * 100