Yogesh
Yogesh

Reputation: 11

I am calling the mean function. But I am getting TypeError: can only concatenate str (not "int") to str

My objective is to find the mean of a column (raised_amount_usd) in a dataframe (say master_frame). However when I try to do so I get a TypeError

    master_frame['raised_amount_usd'].mean()

I expected the code to successfully execute and show the output. However I get:

TypeError: can only concatenate str (not "int") to str

Upvotes: 0

Views: 651

Answers (2)

Yogesh
Yogesh

Reputation: 11

Using the following worked master_frame['raised_amount_usd'].astype(float).mean()

Upvotes: 1

Moshee
Moshee

Reputation: 554

A possible solution would be to try and fill the empty values with 0. You can do that using master_frame['raised_amount_usd'] = master_frame['raised_amount_usd'].fillna(0)

Upvotes: 1

Related Questions