update sanitize_df

This commit is contained in:
iuvbio 2019-01-31 21:38:03 +01:00
parent 21c7004172
commit 1a06fb9bae
1 changed files with 3 additions and 6 deletions

View File

@ -14,11 +14,9 @@ def ods_info(doc):
def sanitize_df(df): def sanitize_df(df):
"""Drops empty rows and columns from the DataFrame and returns it""" """Drops empty rows and columns from the DataFrame and returns it"""
# Delete empty rows # Delete empty rows
rows = len(df) - 1 for i in df.index.tolist()[-1::-1]:
for i in range(rows): if df.iloc[i].isna().all():
row = df.iloc[-1] df.drop(i, inplace=True)
if row.isnull().all():
df = df.iloc[:-1] # TODO: verifiy that the range is not inclusive
else: else:
break break
# Delete empty columns # Delete empty columns
@ -27,5 +25,4 @@ def sanitize_df(df):
if not df[column].isnull().all(): if not df[column].isnull().all():
cols.append(column) cols.append(column)
df = df[cols] df = df[cols]
# len(df.columns)
return df return df