av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

python - 大文本數(shù)據(jù)合并問題思路

瀏覽:94日期:2022-08-12 15:46:37

問題描述

背景:

我有三個csv文件,分別如下:

afile: userid, username, ....bfile: postid, userid, postname, ...cfile: postid, postnum, ...

afile = 10Gbfile = 150Gcfile = 20G

注:各個field的分隔符并不是單個字符(例如逗號),而是一串特殊符號,因?yàn)椴糠謋ield可能會包含某些單字符分隔符,鍵盤上的單字符都試過了,都有包含,所以用了一串幾個字符組成的特殊字符串來分隔,所以并不是嚴(yán)格的csv,這是最蛋疼的地方

目的:

我想合并這三個文件,bfile和cfile根據(jù)postid列合并,合并后再根據(jù)userid列合并afile,最終大概是postid, userid, postname, postnum, username這樣的形式。

目前我的偽代碼如下:

import pandas as pdchunksize = 1000000 # 100W 目前看沒問題 try:resultchunktotal = []bfilereader = pd.read_csv(bfile, iterator=True, engine=’python’, sep=’##’)goon_1 = Truewhile goon_1: try:# 分塊讀取 bfilebfilechunk = bfilereader.get_chunk(chunksize)if not bfilechunk.empty: cfilereader = pd.read_csv(cfile, iterator=True, engine=’python’, sep=’##’) goon_2 = True while goon_2:try: # 分塊讀取 cfile cfilechunk = cfilereader.get_chunk(chunksize) if not cfilechunk.empty:bfilecfilechunk = pd.merge(bfilechunk, cfilechunk, on=’postid’)# 不為空代表 bfile cfile有共同的postidif not bfilecfilechunk.empty: afilereader = pd.read_csv(afile, iterator=True, engine=’python’, sep=’##’) goon_3 = True while goon_3:try: # 分塊讀取afile afilechunk = afilereader.get_chunk(chunksize) if not afilechunk.empty:chunkresult = pd.merge(bfilecfilechunk, afilechunk, on=’’)# 不為空表示有共同的useridif not chunkresult.empty:resultchunktotal.append(chunkresult)except StopIteration: goon_3 = Falseexcept StopIteration: goon_2 = False except StopIteration:goon_1 = Falseif len(resultchunktotal) > 0: pd.concat(resultchunktotal).to_csv(’result.csv’, index=False) except Exception as e:print(e)

但是感覺這樣,很低效,所以跪求各位大神好的思路以及好的工具方法

ps: 這是一道“大數(shù)據(jù)”的偽命題,無非數(shù)據(jù)稍大了點(diǎn)

問題解答

回答1:

別寫代碼啦。看起來是一行 shell 腳本的事情,用 xsv join 子命令。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 亚洲午夜一区 | 亚洲成人免费在线 | 欧美视频一区 | 成人免费福利 | 91久久久久久久久 | 国产精品二区一区二区aⅴ污介绍 | 国产精品区二区三区日本 | 国产三级在线免费观看 | 中文字幕国产视频 | 99国产精品99久久久久久粉嫩 | 97精品国产 | 午夜福利毛片 | 日本一本在线 | 国产在线不卡视频 | 青草视频在线播放 | 伊人av网 | 日本色视频 | 波多野吉衣一二三区乱码 | 久久久久久久久久久国产 | 欧美成人一区二区三区片免费 | 黄色大片av | 精品亚洲一区二区 | 免费黄色av网站 | 黄色小视频在线免费观看 | 日本免费中文字幕 | 成人免费视屏 | 亚洲天堂一区二区三区 | 自拍视频一区 | 黑人精品xxx一区一二区 | 精品国产一区二区在线观看 | 中文字字幕在线中文 | 激情av网 | 91久久久久久久久 | 激情五月激情综合网 | 成人免费黄色大片 | 亚洲第一免费视频 | 日本黄色中文字幕 | 国产精品日日摸天天碰 | 免费观看一区二区三区毛片 | 亚洲福利网 | 9191av|