Jose Blanca
Jose Blanca

Reputation: 105

nan, floats and ints

I'm new to pandas and I have started by trying to read a table completely composed by 1s and 0s and I'm using the read_csv function to do it. Everything goes OK and I get a DataFrame with int64 as column types. The problem appears when I introduce NaN values. In that case I get a DataFrame with column types as float64. Is this the expected behaviour? Is the NaN value incompatible with the int type?

I have also tried to cast the DataFrame with the float column by doing DataFrame(data, dtype=numpy.int64), but in this case I get something like:

                    col1   col2
row1 -9223372036854775808      1
row2                    1      0

Upvotes: 2

Views: 1327

Answers (1)

Wes McKinney
Wes McKinney

Reputation: 105531

NAs / NaN is not supported in integer dtype columns unfortunately (http://pandas.pydata.org/pandas-docs/stable/gotchas.html#support-for-integer-na). But the second thing you describe is a bug. Creating a GitHub issue about it:

https://github.com/pydata/pandas/issues/846

Upvotes: 1

Related Questions