1

I'm a complete newbie to python. I would like to read out an Excel file (150 columns and 10000 lines). Only the values ​​should be output if 2 conditions per line are met. If the conditions are met, the 88th position in the line should be output. With the code listed below, all lines that satisfy "str (" Jan ") are evaluated. The condition" str ("Tom") is ignored. The print commands are only used for verification. Can you give me some tips?

import pandas as pd
df = pd.read_excel("testdaten.xlsx")

df.head()



list = df.values.tolist()

tom_list=[]
for line in list:
  if str("Tom Drewes") and str("Jan") in line:
    tom_list.append(line[88])

print(tom_list)
print(sum(tom_list))
print(len(tom_list))
Donpius
  • 11
  • 1
  • 1
    Short answer (duplicate covers all explanation): You want `if "Tom Drewes" in line and "Jan" in line:` (I removed the `str` constructor calls because the literals are already `str`, and wrapping them in `str()` slows your code to no benefit). – ShadowRanger Sep 15 '20 at 13:25

0 Answers0