将 CSV 文件导入 Python

穆罕默德·阿巴斯

我多次尝试将 CSV 文件导入 python 2.7.15,但失败了。请建议如何在 Python 中导入 CSV。

将 csv 转换为 python

谢谢

更多

在 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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章