Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

type switch from int to float64 after merge creating error

I'm trying to merge two dataframes in Pandas. One of the dataframes has a numerical column whose type is "int64"

However, after the merge, the type is switched to "float64" for some reason. Note that this is not my join column

When I try to access the dataframe, it errors out:

In [56]: account_aggregates.head()
Out[56]: ) failed: TypeError: %d format: a number is required, not numpy.float64>

like image 660
Derek Krantz Avatar asked Oct 15 '25 03:10

Derek Krantz


1 Answers

The reason that the dtype is changed to float64 is because missing values NaN cannot be represented using integer.

With respect to the error message, I had a hunch that it was 'display.float_format' as I answered a question earlier today on this and saw this error. I think that it's because you have to pass a str.format as the value rather than a format string:

pd.set_option('display.float_format', '{:.2g}'.format) as opposed to pd.set_option('display.float_format', '%.2g') as an example.

like image 122
EdChum Avatar answered Oct 16 '25 17:10

EdChum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!