Hi!
I have two problems with my code that used to work fine, maybe python updated or something. I have a dataFrame called data and try to drop rows that has ‘plant name’ either as ‘0’ or is empty. This is the code that fails now:
data = df.iloc[start_row-1:end_row-1, start_col-1:end_col]
names = df.iloc[start_row-2:start_row-1, start_col-1:end_col].astype(str)
names = names.values.tolist()
data.columns = names
data = data.reset_index(drop=True)
data = data[data['plant name'].notnull()]
data = data[data['plant name'] != '0']
It gives me this error for any of the last two rows
Exception: cannot handle a non-unique multi-index
I dont need it to be multi-index and im not even sure how that works. It seems it cannot handle any column having the same name (several of the column names are empty). So i fill these empty column names with index numbers (in the excel file this data comes from) and now it doesnt gove me exception anymore. BUT it still doesnt drop the empty/'0' rows (it used to do that).
- how can i make it except columns with empty names (im just interested in the plant name column anyway). Can I use column index instead of using the ‘plant name' identifier? (it's the forst column that has the names i check for)
- why doesnt it drop the rows anymore? (when i fix it so it doesnt give exception)
- can some other method work for me? I tried looping it, like seen below, but that does nothing (but it doesnt crash? ). The empty rows seem to be ‘nan
in the API so maybe that is not the same as being empty? Also checking for lines where the name is ‘0’, I dont know how to do here…
for index, row in data.iterrows():
if row['plant name'].empty:
data.drop(index, inplace=True)
Thanks a bunch!