Reputation: 3937
I need to convert the Indices of a Series amounts
into its Columns. For example, I need to convert:
1983-05-15 1
1983-11-15 1
1984-05-15 1
1984-11-15 101
into:
1983-05-15 1983-11-15 1984-05-15 1984-11-15
1 1 1 101
I wasn't able to find any documentation on doing this for Series
type Objects specifically and don't know how to do this.
Thank You
Upvotes: 3
Views: 56
Reputation: 394041
There is a built in method to convert a series to a dataframe, to_frame
:
In [146]:
s.to_frame().T
Out[146]:
1983-05-15 1983-11-15 1984-05-15 1984-11-15
1 1 1 101
Upvotes: 1
Reputation: 52246
Build a DataFrame
out of your Series
, then the .T
property returns a transposed version.
In [87]: pd.DataFrame(s).T
Out[87]:
1983-05-15 1983-11-15 1984-05-15 1984-11-15
0 1 1 1 101
Upvotes: 3