CHANGLIN YANG
CHANGLIN YANG

Reputation: 17

How to fill value in specific column ?

For example, in the data, there are NAN values in both profit and country columns. How to fill in the vacancy of profit as 0, while the country does not change.[enter image description here][1]

I tried:

df = df.replace(np.nan, 0)

set Groupby as Country, Metrics as Sum(profit) but the result:

Country Sum(profit)

0 0

httg 0

sdffs 0

In this way, all vacancies will be filled with 0 (including countries that are not needed), and after groupby, there will be an additional category of 0 in Country conlumn(no need).

Upvotes: 1

Views: 65

Answers (1)

NPE
NPE

Reputation: 500257

How to fill value in specific column?

Select the column you want to operate on, and call replace() with inplace=True:

df['Sum(profit)'].replace(np.nan, 0.0, inplace=True)

Upvotes: 2

Related Questions