【发布时间】:2022-12-12 23:36:19
【问题描述】:
我有一个 CSV 文件,我想遍历一列的值(在 python 中)。 csv 文件有 5000 行和两列。如何只遍历第一列而不遍历第二列?
我试着做
for row in df for column in row
但这没有用。我如何解决它?
【问题讨论】:
我有一个 CSV 文件,我想遍历一列的值(在 python 中)。 csv 文件有 5000 行和两列。如何只遍历第一列而不遍历第二列?
我试着做
for row in df for column in row
但这没有用。我如何解决它?
【问题讨论】:
我会使用 pandas 来做这个……就像这样:
import pandas as pd
df = pd.read_csv('blah.csv')
column = df['column_name'] # column_name is the name of the column
for row in column:
print row
【讨论】:
for item, row in df.iterrows():
print(row['column1'])
【讨论】: