python中table是什么_R是Python中的read.table等价物

我正在尝试将我的一些处理工作从R转移到Python.在R中,我使用read.table()来读取非常混乱的CSV文件,它会以正确的格式自动拆分记录.例如.

391788,"HP Deskjet 3050 scanner always seems to break","

I'm running a Windows 7 64 blah blah blah........ake this work permanently?

Update: It might have something to do with my computer. It seems to work much better on another computer, windows 7 laptop. Not sure exactly what the deal is, but I'm still looking into it...

","windows-7 printer hp"

正确分为4列. 1条记录可以分成很多行,并且到处都有逗号.在R我只是做:

read.table(infile, header = FALSE, nrows=chunksize, sep=",", stringsAsFactors=FALSE)

Python中有什么能够同样做到这一点吗?

谢谢!

解决方法:

您可以使用csv模块.

from csv import reader

csv_reader = reader(open("C:/text.txt","r"), quotechar="\"")

for row in csv_reader:

print row

['391788', 'HP Deskjet 3050 scanner always seems to break', "

I'm running a Windows 7 64 blah blah blah........ake this work permanently?

\n\n

Update: It might have something to do with my computer. It seems to work much better on another computer, windows 7 laptop. Not sure exactly what the deal is, but I'm still looking into it...

\n", 'windows-7 printer hp']

输出长度= 4

标签:python,r,read-table

来源: https://codeday.me/bug/20190517/1121188.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值