我多次尝试将 CSV 文件导入 python 2.7.15,但失败了。请建议如何在 Python 中导入 CSV。
谢谢
在 Python 中导入 csv 文件有两种方法。
第一:使用标准 Python csv
import csv
with open('filename.csv') as csv_file:
csv_read=csv.reader(csv_file, delimiter=',')
第二:使用 pandas
import pandas as pd
data = pd.read_csv('filename.csv')
data.head() # to display the first 5 lines of loaded data
我建议导入 usingpandas
因为这是更方便的方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句