小编bic*_*cta的帖子

pandas read_csv 数据类型定义:int、int64、'Int64'

有人可以指出一个好的方向来理解 pandas.read_csv 期间定义 dtype 的方式(看似)不一致吗?

dtype = int # --> 如果空白值会产生错误
dtype = int32、int64 和 Int64 # --> 未定义
dtype = 'Int64' # --> 正确地将 csv 文件读取为整数并包含空白值

  • 为什么 'Int64' 需要引号,而 str、float、int、object 不需要引号?
  • 我没有找到明确定义 pandas.read_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)

file-io dataframe pandas

7
推荐指数
1
解决办法
4298
查看次数

标签 统计

dataframe ×1

file-io ×1

pandas ×1