MT467
MT467

Reputation: 698

swap pandas column to values in another column

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?

Upvotes: 0

Views: 61

Answers (1)

gal peled
gal peled

Reputation: 482

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:]

Upvotes: 1

Related Questions