簡體   English   中英

如何在不使用 pandas 的情況下逐行排列 append 兩個.csv 文件

[英]How to row wise append two .csv files without using pandas

我想 append 兩個.csv 具有相同列數/名稱的文件並保存輸出文件。 但是我不想使用 pandas concat 或 pandas read_csv。 有沒有辦法使用純 python 'with open' 來實現這一點?

像這樣的東西應該工作:

# read first file
with open('file1.csv', 'r') as txt:
    lines = txt.readlines()

# extend the list with the lines from the second file
with open('file2.csv', 'r') as txt:
    lines.extend(txt.readlines())

# remove \n from the end of each line
lines = [line.strip() for line in lines]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM