when I have a DataFrame with np.uint64 values
import pandas as pd
import numpy as np
df = pd.DataFrame(columns=['a','b'])
df.a = [1, 3]
df.b = [1, 3]
df = df.astype({'a': np.uint64, 'b': np.uint64})
print(df.info())
it returns
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2 entries, 0 to 1
Data columns (total 2 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 a 2 non-null uint64
1 b 2 non-null uint64
dtypes: uint64(2)
memory usage: 160.0 bytes
None
When I now try to add a cell to the DataFrame:
x = np.uint64(5)
print(type(x))
returns
<class 'numpy.uint64'>
and
df.at[2, 'a'] = x
print(type(df.at[2, 'a']))
print(df.dtypes)
returns
<class 'numpy.float64'>
<class 'pandas.core.frame.DataFrame'>
Int64Index: 3 entries, 0 to 2
Data columns (total 2 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 a 3 non-null float64
1 b 2 non-null float64
dtypes: float64(2)
memory usage: 180.0 bytes
None
Why does the type of the columns and values change from np.uint64 to float64?