Convert Series to pandas DataFrame in Python (2 Examples) | Create Column | to_frame() & DataFrame()

Опубликовано: 30 Сентябрь 2022
на канале: Statistics Globe
442
7

How to convert a pandas Series to a DataFrame in the Python programming language. More details: https://statisticsglobe.com/convert-s...
Python code of this video:

import pandas as pd # Load pandas

my_ser = pd.Series([1, 3, 5, 7, 9]) # Create example Series
print(my_ser) # Print example Series
0 1
1 3
2 5
3 7
4 9
dtype: int64

my_data1 = my_ser.to_frame('x') # Convert Series to DataFrame
print(my_data1) # Print pandas DataFrame

my_data2 = pd.DataFrame({'x': my_ser}) # Convert Series to DataFrame
print(my_data2) # Print pandas DataFrame

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe  
Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – R Programming Group for Discussions & Questions:   / 12555223  
LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534  
Twitter:   / joachimschork  

Music by bensound.com