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
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With