![](/img/trans.png)
[英]How to read a csv row wise and convert to a dataframe column using pandas?
[英]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.