我试图消除列和列的值索引,并用'kw'替换列的第一个值。
尝试.drop失败
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
答案 0 :(得分:0)
如果kw
是要用作新索引的列,则可以执行以下操作:
df.set_index('kw', inplace=True)