![](/img/trans.png)
[英]Read multiple CSV files and insert data into a table using python multiprocessing without using pandas
[英]Python: Read in multiple csv files from a directory into a dictionary without using Pandas
我有一個包含多個 csv 的目錄,我想讀入一個字典。 字典將使用原始文件名作為鍵,使用 csv 的內容作為值。 我不想使用 pandas 因為我是 Python 的新手,想在拔出大炮之前先了解這些任務。 我想使用 DictReader 來完成這項任務。 這是我到目前為止的代碼。 它一次只能處理一個文件。 非常感謝您的幫助。
def read_lines():
data = []
with open('vari_late_low_scores.csv', newline='') as stream:
reader = csv.reader(stream, delimiter=',', skipinitialspace=True)
for row in reader:
data.append(row)
return data
謝謝!
我認為您可以遍歷文件並將文件名傳遞給 function
def read_lines(fileName):
data = []
with open( fileName + '.csv', newline='') as stream:
reader = csv.reader(stream, delimiter=',', skipinitialspace=True)
for row in reader:
data.append(row)
return data
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.