gpt4 book ai didi

python - numpy.genfromtxt : delimiter =',' fails to split string

转载 作者:太空宇宙 更新时间:2023-11-03 13:20:52 25 4
gpt4 key购买 nike

我不明白为什么 numpy.genfromtxt 不能使用 delimiter="," 正确拆分以下字符串,而它适用于中的大多数其他字符串我的 block 。

chunk[12968]
Out[143]: '2901869281,3279442095,2012-12-15T23:00:00.003Z,Sacramento,CA,R#3817874,United States,38.583,-121.498,11, 8, 6, 5, 1, 0, 2, 3, 3, 5, 3, 3, 2, 2, 6, 6, 1, 2, 3, 0, 1, 1, 0, 0, 2, 2, 2, 2, 1, 0, 0, 2, 1, 0, 1, 1, 2, 0, 3, 1, 1, 1, 1, 0, 0, 4, 0, 0, 0, 1, 3, 1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 9, 0, 0, 0, 2, 3, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0,130\n'

我希望得到一个形状为 (110,) 的数组,但得到以下结果

genfromtxt([chunk[12968]],delimiter=",",dtype=np.int64)
Out[142]:
array([2901869281, 3279442095, -1, -1, -1,
-1], dtype=int64)

请注意,我正在使用 itertools 中的 izip_longest 以这种方式按 block 读取大型 *csv:

with open('events.csv','r') as:
for chunk in izip_longest(*[f] *50000):
...

感谢您的帮助。

最佳答案

genfromtxt()comments 参数默认为 '#',因此输入中 # 之后的所有内容都会被忽略:

2901869281,3279442095,2012-12-15T23:00:00.003Z,Sacramento,CA,R#3817874,United States,...
^ start of comment

关于python - numpy.genfromtxt : delimiter =',' fails to split string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14435162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com