10

I need help to get the position of the column or another way to read in the column two step left of the column Spannung.

Exceldata = pd.read_excel(str(Dateien[0]), header=[2])
print Dateien[0]
Spannung = Exceldata.columns[Exceldata.columns.str.contains('Spannung effektiv L1')]
print Spannung
gareththegeek
  • 2,362
  • 22
  • 34
A.Boss
  • 217
  • 1
  • 5
  • 9

1 Answers1

13

IIUC you can use .get_loc

So:

pos = Exceldata.columns.get_loc(Spannung[0])

then you can index left:

other_col = Exceldata.columns[pos -2]

Example:

In [169]:
df = pd.DataFrame(columns=['hello','world','python','pandas','Spannung effektiv L1', 'asdas'])
spannung = df.columns[df.columns.str.contains('Spannung')]
spannung

Out[169]:
Index(['Spannung effektiv L1'], dtype='object')

In [178]:
pos = df.columns.get_loc(spannung[0])
df.columns[pos-2]

Out[178]:
'python'
EdChum
  • 376,765
  • 198
  • 813
  • 562