Reputation: 49
I need ideas to iterate from index 100 down and if you find an empty value fill it with zero. The idea is to do it in each of the columns. For example: Is so
... ... ... ... ...
... ... ... ... ...
99 -6661,39775 -6080,24775 -6669,13875 NaN
100 -6669,13875 -6303,48 NaN NaN
101 -6687,2345 NaN NaN NaN
102 -6676,43775 NaN NaN NaN
And it should look like this
... ... ... ... ...
... ... ... ... ...
99 -6661,39775 -6080,24775 -6669,13875 NaN
100 -6669,13875 -6303,48 0 0
101 -6687,2345 0 0 0
102 -6676,43775 0 0 0
It is an excel file ... I am using the pandas library. And more or less what I try to do is to filter the data eliminating columns that do not have the measurements, as I show in the following code:
todos = []
for f in glob.glob('*.xlsx'):
df = pd.read_excel(f, sheet_name='Medidas')
df = df.drop(df.index[[0,1,2,5,6]])
df = df.drop(df.index[len(df)-1])
#Here should be the condition of the problem
df = df.dropna(axis=1, how= 'any', thresh=None, subset=None, inplace=False)
todos.append(df)
df = pd.read_excel(f)
df = pd.concat(todos, axis=1)
df = df.loc[:,~df.columns.duplicated()]
Upvotes: 0
Views: 40
Reputation: 36
With this code, you can fill nan values after 100's rows to the last row.
df.loc[101:]=df.loc[101:].fillna(0)
Upvotes: 1