从 pandas 数据帧列号中减去预定义的值并返回新编号



我有一个形状为(3000,60630)的熊猫数据帧。我正在研究一个二元分类问题。有 12126 个焊盘细节,每个细节代表焊盘的一个功能。

    First 12126 columns-feature 1
    2nd 12126 columns-feature 2
    3rd 12126 columns-feature 3
    4th 12126 columns-feature 4
    5th 12126 columns feature 5
In total 60630 columns.

为了简单起见,我给出了从 1 到 60630 的列号。但现在我需要检索原始垫详细信息。

每列 12126 列,我需要从 1 重新开始,我不想在原始数据帧中进行更改。出于报告目的,我需要这些细节。

 Eg:12127 corresponds to pad1
60630 corresponds to pad 12126

IIUC:

In [5]: df = pd.DataFrame(np.random.randint(100, size=(3, 60630)))
In [6]: df.columns
Out[6]: RangeIndex(start=0, stop=60630, step=1)
In [7]: i = 0
In [8]: df.iloc[:, 12126*i:12126*(i+1)].columns
Out[8]: RangeIndex(start=0, stop=12126, step=1)
In [9]: i = 1
In [10]: df.iloc[:, 12126*i:12126*(i+1)].columns
Out[10]: RangeIndex(start=12126, stop=24252, step=1)

最新更新