Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8812145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:32:20+00:00 2026-06-14T03:32:20+00:00

I have a Pandas Dataframe as below: itm Date Amount 67 420 2012-09-30 00:00:00

  • 0

I have a Pandas Dataframe as below:

      itm Date                  Amount 
67    420 2012-09-30 00:00:00   65211
68    421 2012-09-09 00:00:00   29424
69    421 2012-09-16 00:00:00   29877
70    421 2012-09-23 00:00:00   30990
71    421 2012-09-30 00:00:00   61303
72    485 2012-09-09 00:00:00   71781
73    485 2012-09-16 00:00:00     NaN
74    485 2012-09-23 00:00:00   11072
75    485 2012-09-30 00:00:00  113702
76    489 2012-09-09 00:00:00   64731
77    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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:32:21+00:00Added an answer on June 14, 2026 at 3:32 am

    I believe DataFrame.fillna() will do this for you.

    Link to Docs for a dataframe and for a Series.

    Example:

    In [7]: df
    Out[7]: 
              0         1
    0       NaN       NaN
    1 -0.494375  0.570994
    2       NaN       NaN
    3  1.876360 -0.229738
    4       NaN       NaN
    
    In [8]: df.fillna(0)
    Out[8]: 
              0         1
    0  0.000000  0.000000
    1 -0.494375  0.570994
    2  0.000000  0.000000
    3  1.876360 -0.229738
    4  0.000000  0.000000
    

    To fill the NaNs in only one column, select just that column. in this case I’m using inplace=True to actually change the contents of df.

    In [12]: df[1].fillna(0, inplace=True)
    Out[12]: 
    0    0.000000
    1    0.570994
    2    0.000000
    3   -0.229738
    4    0.000000
    Name: 1
    
    In [13]: df
    Out[13]: 
              0         1
    0       NaN  0.000000
    1 -0.494375  0.570994
    2       NaN  0.000000
    3  1.876360 -0.229738
    4       NaN  0.000000
    

    EDIT:

    To avoid a SettingWithCopyWarning, use the built in column-specific functionality:

    df.fillna({1:0}, inplace=True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the data below saved as a pandas dataframe . With this data,
I have a pandas DataFrame with a date column. It is not an index.
I have the following pandas Dataframe: from pandas import DataFrame, MultiIndex index = MultiIndex.from_tuples(zip([21,22,23],[45,45,46]),
Suppose I have the example TimeSeries below: ts = pandas.TimeSeries({'a':[1,2,3,4,5], 'b':[6,7,8,9,10]}) The best method
Suppose I have a Pandas dataframe df has columns a,b,c,d...z . And I want
I have a column in a pandas DataFrame that I would like to split
I have a pandas dataframe consisting of 23 series with a default sequential index
Assume I have a pandas DataFrame with two columns, A and B. I'd like
I have a Python pandas DataFrame rpt : rpt <class 'pandas.core.frame.DataFrame'> MultiIndex: 47518 entries,
I have a dataframe generated from Python's Pandas package. How can I generate heatmap

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.