Python 从索引100到结尾,我如何完成零?
我需要想法从索引100向下迭代,如果你发现一个空值,用零填充它。我们的想法是在每一列中都这样做。 例如: 是这样吗 应该是这样的Python 从索引100到结尾,我如何完成零?,python,pandas,Python,Pandas,我需要想法从索引100向下迭代,如果你发现一个空值,用零填充它。我们的想法是在每一列中都这样做。 例如: 是这样吗 应该是这样的 ... ... ... ... ... ... ... ... ... ... 99 -6661,39775 -6080,24775 -6669,13875 NaN 100 -6669
... ... ... ... ...
... ... ... ... ...
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
这是一个excel文件。。。我正在使用熊猫图书馆。我尝试做的或多或少是过滤数据,消除没有测量值的列,如我在以下代码中所示:
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()]
使用此代码,可以将100行之后的nan值填充到最后一行
df.loc[101:]=df.loc[101:].fillna(0)
df.loc[101:]=df.loc[101:].fillna(0)