Convert pandas Series to DataFrame Convert pandas Series to DataFrame python python

Convert pandas Series to DataFrame


Rather than create 2 temporary dfs you can just pass these as params within a dict using the DataFrame constructor:

pd.DataFrame({'email':sf.index, 'list':sf.values})

There are lots of ways to construct a df, see the docs


to_frame():

Starting with the following Series, df:

emailemail1@email.com    Aemail2@email.com    Bemail3@email.com    Cdtype: int64

I use to_frame to convert the series to DataFrame:

df = df.to_frame().reset_index()    email               00   email1@email.com    A1   email2@email.com    B2   email3@email.com    C3   email4@email.com    D

Now all you need is to rename the column name and name the index column:

df = df.rename(columns= {0: 'list'})df.index.name = 'index'

Your DataFrame is ready for further analysis.

Update: I just came across this link where the answers are surprisingly similar to mine here.


One line answer would be

myseries.to_frame(name='my_column_name')

Or

myseries.reset_index(drop=True, inplace=True)  # As needed