Dask - 连接两个同列数据帧不起作用



我有两个没有标题行的数据帧,它们都有相同的逗号分隔列。我试着用把它们读入一个数据帧

dfoutputs = dd.read_csv(['outputsfile.csv', 'outputsfile2.csv'], names=colnames, header=None, dtype={'firstnr': 'Int64', 'secondnr': 'Int64', 'thirdnr': 'Int64', 'fourthnr': 'Int64'})

但是该数据帧仅包含CCD_ 1行。

读取和连接的类似问题:

colnames=['firstnr', 'secondnr', 'thirdnr', 'fourthnr'] 
dfoutputs = dd.read_csv('outputsfile.csv', names=colnames, header=None, dtype={'firstnr': 'Int64', 'secondnr': 'Int64', 'thirdnr': 'Int64', 'fourthnr': 'Int64'})
print(dfoutputs.head(10))
dfoutputs2 = dd.read_csv('outputsfile2.csv', names=colnames, header=None, dtype={'firstnr': 'Int64', 'secondnr': 'Int64', 'thirdnr': 'Int64', 'fourthnr': 'Int64'})
print(dfoutputs2.head(10))
dfnew  = dd.concat([dfoutputs, dfoutputs2])
print(dfnew.head(10))

输出:

firstnr  secondnr  thirdnr      fourthnr
0  0        0     0      5000000000
1  1        0     0      5000000000
2  2        0     0      5000000000
3  3        0     0      5000000000
4  4        0     0      5000000000
5  5        0     0      5000000000
firstnr  secondnr  thirdnr      fourthnr
0  11       0     0      5000000000
1  12       0     0      5000000000
firstnr  secondnr  thirdnr      fourthnr
0  0        0     0      5000000000
1  1        0     0      5000000000
2  2        0     0      5000000000
3  3        0     0      5000000000
4  4        0     0      5000000000
5  5        0     0      5000000000

如何将两个csv组合到同一个Dask数据帧?

如TennisTechBoy在评论中所建议:

f=open("outputsfile.csv", "a")
f2=open("outputsfile2.csv", "r")
f2content = f2.readlines()
for i in range(len(f2content)):
f.write(f2content[i])
f.close()
f2.close()

从内存的角度来看,可能需要一种在Dask中实现这一点的方法。

最新更新