简体   繁体   English

如何从python中的csv文件读取列

[英]How to read a column from a csv file in python

I currently am using pandas to read from a csv file but I'm trying to remove the index column, Name and dtype from my output 我目前正在使用熊猫从csv文件读取,但是我正在尝试从输出中删除索引列,名称和dtype

import pandas as pd
df = pd.read_csv('C:/Users/Book2.csv')
list = [df['Column1']]
print (list)

Output: 输出:

[0     ST
1    VC
2     ST
3     ST
4    ST
5     CO
6     UT
Name: Column1, dtype: object]

This kind of depends on what you are trying to do. 这种类型取决于您要执行的操作。 If you just want the values, you can add list = df.values to the list. 如果只需要这些值,则可以将list = df.values添加到列表中。 If you are trying to append to a list, you can do list += df.values after initializing list . 如果您尝试追加到列表,则可以在初始化list之后执行list += df.values

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM