如何消除python数据帧中列和行的索引值?

2024-05-18 10:17:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图删除列和行,它们表示值的索引,并用“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


Tags: theadddfnewindexmaindefwith