1#To convert a series to a dataframe simply apply the to_frame() method
2#to the series
3s.to_frame()
1>>> s = pd.Series(["a", "b", "c"],
2... name="vals")
3>>> s.to_frame()
4 vals
50 a
61 b
72 c
8
1import pandas as pd
2
3data = {'First_Name': ['Jeff','Tina','Ben','Maria','Rob']}
4df = pd.DataFrame(data, columns = ['First_Name'])
5
6print(df)
7# First_Name
8#0 Jeff
9#1 Tina
10#2 Ben
11#3 Maria
12#4 Rob
13
14print(type(df))
15# <class 'pandas.core.frame.DataFrame'>
16
17df = df.squeeze() # <- Converts to a pandas series
18print(df)
19#0 Jeff
20#1 Tina
21#2 Ben
22#3 Maria
23#4 Rob
24#Name: First_Name, dtype: object
25
26print(type(df))
27# <class 'pandas.core.series.Series'>