Home > database >  swap pandas column to values in another column
swap pandas column to values in another column

Time:09-21

I have a pandas dataframe- got it from API so don't have much control over the structure of it- similar like this:

enter image description here

I want to have datetime a column and value as another column. Any hints?

CodePudding user response:

you can use T to transform the dataframe and then reseindex to create a new index column and keep the current column you may need to change its name form index

df = df.T.reset_index()
df.columns = df.iloc[0]
df = df[1:]
  • Related