我有一个CSV文件,大约有2000条记录。
每条记录都有一个字符串和一个类别。
This is the first line, Line1
This is the second line, Line2
This is the third line, Line3
我需要把这个文件读成这样的列表
List = [('This is the first line', 'Line1'),
('This is the second line', 'Line2'),
('This is the third line', 'Line3')]
如何使用Python将这个csv
导入到我需要的列表中?
为Python 3更新:
输出:
Pandas非常擅长处理数据。下面是一个如何使用它的示例:
一个很大的优势是pandas自动处理标题行。
如果你没听说过Seaborn,我建议你看看。
另请参见:How do I read and write CSV files with Python?
熊猫2
df的内容是:
口述的内容是
熊猫3
lists
的内容是:使用^{} 模块(Python 2.x):
如果需要元组:
Python 3.x版本(作者@seokhoonlee)
相关问题 更多 >
编程相关推荐