【问题标题】:How to loop through specific rows, columns如何循环遍历特定的行、列
【发布时间】:2020-08-05 15:38:11
【问题描述】:

我想遍历我的 xls 文件的特定范围。如图所示,您可以看到我在行之间的某些点上有一些十字架。我需要将它们的值放入我的 python 程序中,以将它们镜像到一个数组中。所以我想我只是用 pandas 遍历数据框并制作一个简单的 if 函数。

到目前为止,我的函数看起来像这样:

import pandas as pd
import xlrd

df = pd.read_excel('test.xls', sheet_name='Tabelle1')


for index, rows in df.iterrows():
    if rows[index] == "x":
        print("test1")

enter image description here

【问题讨论】:

标签: python pandas loops


【解决方案1】:
df = pd.read_excel('test.xls', sheet_name='Tabelle1')
sliced_df = df.ix[8:26,]# slice base on the row index
for index, rows in sliced_df.iterrows():
    if rows[index] == "x":
        print("test1")

您可以使用 ix 对 pandas 行进行切片。 Google 关于 pandas ix。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-11
    • 2021-12-14
    • 1970-01-01
    • 1970-01-01
    • 2019-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多