[英]How can I append the content of multiple text file to a new text files based on specific conditions in python?
[英]How can I read multiple text files and extract data with some conditions, then add columns based on another lookup table in python
我是python的初學者,我試圖使用python打開多個文本文件(總共5g數據),並且僅選擇c =“ string111”條件的行,然后嘗試根據查找表(csv)添加另一列文件),然后最后編寫一個cvs或excel文件。
例如:文件看起來像:
a b c d
string1 string11 string111 678
string2 string22 string222 890
string3 string33 string333 2739
我還有另一個查找csv文件:
a b c e
string1 string11 string111 string1111
string2 string22 string222 string2222
string3 string33 string333 string1111
最后,我想獲取如下的csv文件:
e d
string1111 98032 (this is aggregate data)
string2222 677...
由於數據太大,因此很難使用excel對其進行處理。 只是想知道python代碼來解決這個簡單的問題。
謝謝!
實際上,Excel完全能夠處理此問題。 使用Excel 2010和2013,您可以使用免費的Power Query加載項,在Excel 2016中,它在“數據”功能區上稱為“獲取和轉換”。
為查詢CSV創建查詢,並將其僅作為連接加載。
然后為一個CSV文件創建查詢,應用過濾器,然后與查找CSV合並並執行您要執行的任何其他操作。
可以將結果加載到工作表中並另存為CSV。
只需單擊功能區圖標即可完成上述操作,並且可以在高級編輯器中修改Power Query語言“ M”中生成的腳本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.