Skip to content

DataFrame.cumsum() breaks when using a DataFrame that was filled using the isnan() function #5103

Closed
@jdavidheiser

Description

@jdavidheiser

Most help documents I've seen suggest using the fillna() function to fill a DataFrame. However, if you try to use the results of that fill operation with other functions, it can break. For example, the following code:

df = DataFrame(index=["A","B","C"], columns = [1,2,3,4,5]) df2 = df.fillna(1) df2.cumsum()

Fails with the following error message:

 File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/pandas/core/generic.py", line 827, in cumsum
    mask = np.isnan(self.values)
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

However, creating a DataFrame filled with ones using the following works just fine:

df = DataFrame(np.ones((3,5)),index=["A","B","C"], columns = [1,2,3,4,5])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions