Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

How to replace NaN values in a dataframe column

$
0
0

I have a Pandas Dataframe as below:

      itm Date                  Amount 67    420 2012-09-30 00:00:00   6521168    421 2012-09-09 00:00:00   2942469    421 2012-09-16 00:00:00   2987770    421 2012-09-23 00:00:00   3099071    421 2012-09-30 00:00:00   6130372    485 2012-09-09 00:00:00   7178173    485 2012-09-16 00:00:00     NaN74    485 2012-09-23 00:00:00   1107275    485 2012-09-30 00:00:00  11370276    489 2012-09-09 00:00:00   6473177    489 2012-09-16 00:00:00     NaN

When I try to apply a function to the Amount column, I get the following error:

ValueError: cannot convert float NaN to integer

I have tried applying a function using math.isnan, pandas'.replace method, .sparse data attribute from pandas 0.9, if NaN == NaN statement in a function; I have also looked at this Q/A; none of them works.

How do I do it?


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>