in Education by
I have a 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 .isnan from the Math Module I have tried the pandas .replace attribute I tried the .sparse data attribute from pandas 0.9 I have also tried if NaN == NaN statement in a function. I have also looked at this article How do I replace NA values with zeros in an R dataframe? whilst looking at some other articles. All the methods I have tried have not worked or do not recognize NaN. Any Hints or solutions would be appreciated. Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
You can use DataFrame.fillna() method for this problem. This function fills the null value with the given value in the dataframe. For example: 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

Related questions

0 votes
    I want to get a list of the column headers from a pandas DataFrame. The DataFrame will come from user input so I don ... 'gdp', 'cap'] Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I'm starting with input data like this df1 = pandas.DataFrame( { "Name" : ["Alice", "Bob", "Mallory", ... Any hints would be welcome. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I have a 20 x 4000 dataframe in python using pandas. Two of these columns are named Year and quarter. I'd ... anyone help with that? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I have a dataset |category| cat a cat b cat a I'd like to be able to return something like (showing unique values ... cat a 2 cat b 1 Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    How do I get the index column name in python pandas? Here's an example dataframe: Index Title Column 1 Apples 1 ... how to do this? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    I want to select rows from a DataFrame based on values in some column in pandas, How can I do it? I ... WHERE column_name = some_value Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I am trying to groupby a column and compute value counts on another column. import pandas as pd dftest = pd. ... Amt, already exists Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I have a pandas data frame like: a b A 1 A 2 B 5 B 5 B 4 C 6 I want to group by the ... do something like this using pandas groupby? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I'm trying to get the number of rows of dataframe df with Pandas, and here is my code. Method 1: total_rows ... What am I doing wrong? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    def multiple_dfs(xyz_file, sheet, *args): row=2 writer = pd.ExcelWriter(xyz_file, engine='openpyxl') df = pd. ... help me over this? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Working with census data, I want to replace NaNs in two columns ("workclass" and "native-country") with the ... way to do this? Select the correct answer from above options...
asked Feb 3, 2022 in Education by JackTerrance
0 votes
    How to replace the values of NA with zeros in some column and data frame I have? Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    How to replace the values of NA with zeros in some column and data frame I have? Select the correct ... Questions, Core Hadoop MCQ,core Hadoop interview questions for experienced...
asked Oct 30, 2021 in Education by JackTerrance
0 votes
    I'm starting from the pandas DataFrame docs here: http://pandas.pydata.org/pandas-docs/stable/dsintro.html I'd ... =1)] print valdict Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    An irregular time series data is stored in a pandas.DataFrame. A DatetimeIndex has been set. I need the ... seemingly simple operation? Select the correct answer from above options...
asked Feb 3, 2022 in Education by JackTerrance
...