Pandas has a method (.to_frame()
) to convert a Series to Data Frame. We will create a sample Pandas Data Frame:
import pandas as pd df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]}) df
Let’s call column B which is a Series.
df['B']
We can easily convert it to Data Frame by running:
df['B'].to_frame()
Another approach, not the most efficient though, is to run:
pd.DataFrame(df['B'])