pythoncsv数据类型_Python-如何获取CSV文件中所有列的数据类型?

本文探讨了如何使用pandas读取CSV文件并获取每列数据类型。通过`pd.read_csv()`加载数据,并利用`df.dtypes`可以查看列数据类型。对于大型文件,可以使用`nrows`参数只读取部分行来提高效率。同时,通过循环遍历`df.dtypes.iteritems()`可以详细列出所有列及其对应的数据类型。
摘要由CSDN通过智能技术生成

1586010002-jmsa.png

I am trying to get all data types from a CSV file for each column.

There is no documentation about data types in a file and manually checking will take a long time (it has 150 columns).

Started using this approach:

df = pd.read_csv('/tmp/file.csv')

>>> df.dtypes

a int64

b int64

c object

d float64

Is above approach good enough or there is a better approach to figure out data types?

Also - file has 150 columns. When I type df.types - I can see only 15 or so columns. How to see them all?

解决方案

Depending on the size of your file, you might be able to save some time by only reading in the first few rows, using the nrows argument of pd.read_csv:

df = pd.read_csv('/tmp/file.csv', nrows=25)

This is only useful if you know for sure

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值