有人可以指出一个好的方向来理解 pandas.read_csv 期间定义 dtype 的方式(看似)不一致吗?
dtype = int # --> 如果空白值会产生错误
dtype = int32、int64 和 Int64 # --> 未定义
dtype = 'Int64' # --> 正确地将 csv 文件读取为整数并包含空白值
import pandas as pd; print(pd.__version__)
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
MY_DTYPES = {
'date_string': str,
'description': str,
# 'ValueError_Integer_column_has_NA_values': int,
# 'int32_is_not_defined': int32,
# 'int64_is_not_defined': int64,
# 'Int_64_is_not_defined': Int64,
'Int64_with_quote_and_NaN': 'Int64', # !! THIS WORKS !!
'quantity': float,
'total': float}
f = 'dataset.csv'
df = pd.read_csv(f, …Run Code Online (Sandbox Code Playgroud)