2

I am trying to eliminate the column and the row which state the index of the values and replace the first value of my column by 'kw'.

Have tried .drop without success

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)

This gives me .xlsx output

1 Answer 1

1

If kw is the column you want to be your new index, you can do this:

df.set_index('kw', inplace=True)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.