How to convert pandas Series to DataFrame
I have a pandas Series as se:
wind yes
humidity high
weather sunny
temp hot
conclusion bad
Name: 1, dtype: object
And I want to convert it into a dataframe like:
| weather| temp | humidity | wind | conclusion
0 | sunny | hot | high | yes | bad
I've tried
pd.DataFrame(se)
but it turns out to be something else
wind yes
humidity high
weather sunny
temp hot
conclusion bad
Use to_frame
and transpose your new dataframe:
df = sr.to_frame(0).T
print(df)
# Output:
wind humidity weather temp conclusion
0 yes high sunny hot bad
Setup
data = {'wind': 'yes',
'humidity': 'high',
'weather': 'sunny',
'temp': 'hot',
'conclusion': 'bad'}
sr = pd.Series(data, name=1)
print(sr)
# Output
wind yes
humidity high
weather sunny
temp hot
conclusion bad
Name: 1, dtype: object