dataframe中的数据类型

1 建表时,如果赋的是空值,默认是float类型,所以要指定数据类型。

特别是建了空表后,与其它表融合时,要注意数据类型的改变。

df = pd.DataFrame({ 'a': [],
                    'b': [],
                  })
print(df.info())
df = pd.DataFrame({ 'a': [],
                    'b': [],
                 },         dtype = np.int64)
print(df.info())
# <class 'pandas.core.frame.DataFrame'>
# RangeIndex: 0 entries
# Data columns (total 2 columns):
# a    0 non-null float64
# b    0 non-null float64
# dtypes: float64(2)
# memory usage: 76.0 bytes
# None
# <class 'pandas.core.frame.DataFrame'>
# RangeIndex: 0 entries
# Data columns (total 2 columns):
# a    0 non-null int64
# b    0 non-null int64
# dtypes: int64(2)
# memory usage: 76.0 bytes
# None

参考:https://blog.csdn.net/jinruoyanxu/article/details/79150896

猜你喜欢

转载自www.cnblogs.com/xxswkl/p/10963708.html