dataframe Data Type

1 built form, if assigned a null value, default is of type float, so to specify the data type.

Especially after the construction of the empty table, and other tables when fused to note that the data type of change.

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

Reference: https://blog.csdn.net/jinruoyanxu/article/details/79150896

Guess you like

Origin www.cnblogs.com/xxswkl/p/10963708.html