我试图删除列和行,它们表示值的索引,并用“kw”替换我列的第一个值
我试过了。失败了
def main():
df_old_m, df_new_m = open_file_with_data_m(file_old_m, file_new_m)
#combine two dataframes together
df = df_old_m.append(df_new_m)
son=df["son"]
gson=df["gson"]
#add son
df_old_m = df["seeds"].append(son)
#add gson
df_old_m = df_old_m.append(gson)
#deleted repeated values
df_old_m = df_old_m.drop_duplicates()
#add kw as the header of the list
df_old_m.loc[-1] = 'kw' # adding a row
df_old_m.index = df_old_m.index + 1 # shifting index
df_old_m.sort_index(inplace=True)
这给了我.xlsx output
如果
kw
是要作为新索引的列,则可以执行以下操作:df.set_index('kw', inplace=True)
相关问题 更多 >
编程相关推荐