1

I have a dataframe of values that i'd like to turn into a single row where each key is a column and each value is a the value, with the result being a single row. It seems like it should be a simple task but im struggling to get it done. I appreciate any help wit this

Current Table

key value
var1 value1
var2 value2
var3 value3
var4 value4
var5 value5
var6 value6
var7 value7

Goal Table

var1 var2 var3 var4 var5 var6 var7
value1 value2 value3 value4 value5 value6 value7
Michael Lopez
  • 79
  • 2
  • 11

1 Answers1

0

You can use the DataFrame.Transpose() function

for example

df = pd.DataFrame({'A':[1, 2, 3, 4, 5, 6], 'B': ['a', 'b', 'c', 'd', 'e', 'f']})

   A  B
0  1  a
1  2  b
2  3  c
3  4  d
4  5  e
5  6  f

now

df.Transpose()

   0  1  2  3  4  5
A  1  2  3  4  5  6
B  a  b  c  d  e  f

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.transpose.html#pandas.DataFrame.transpose

and you may need this in the futer

https://pandas.pydata.org/docs/user_guide/reshaping.html

Evert Acosta
  • 81
  • 1
  • 7