0

I have this data frame:

key         value
EXE_PATH     /opt/IBM/ITM/aix526/ux/bin/kuxagent 
EXE_NAME      kuxagent 

I need to transform this data frame to be like this. Key values need to be column names and values need to be row entries

EXE_PATH                             EXE_NAME
/opt/IBM/ITM/aix526/ux/bin/kuxagent   kuxagent 
2
  • In general, you need a third column which relates each pair of records to a single group. Commented Apr 19, 2022 at 4:16
  • 1
    df.T. Yes, it is that simple Commented Apr 19, 2022 at 4:37

2 Answers 2

1

You can do a transpose, with some additional steps to clean up the key and value:

df.set_index('key').T.reset_index(drop=True)

But perhaps a better question to ask is how did you end up with the first dataframe and if it is possible to work on the input before trying to fight pandas in how it represents your data as a dataframe.

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

Comments

1

If df looks like this.

key value
0 EXE_PATH /opt/IBM/ITM/aix526/ux/bin/kuxagent
1 EXE_NAME kuxagent

You can make the key's the columns and the values the rows using the code below.

new_df = df.T.iloc[1:, :]
new_df.columns = df["key"]
new_df 

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.