Pandas Series to DataFrame

Previous
Next

In this post, we will see how to convert Pandas Series to DataFrame.


You can use series.to_frame() method to convert Pandas Series to DataFrame.to_frame() returns DataFrame representation of the series.

Here,
name: It is subsitute for series name, it will be None if not provided.

Convert series to dataframe

You can convert Series to DataFrame using series.to_frame() method.

Here is an example:

Output:

Convert Series to DataFrame with column name

You can convert Series to DataFrame using series.to_frame() method and pass name parameter to label column.

Here is an example:

Output:

Pandas series to dataframe with index of Series as columns

Let’s say you have series and you want to convert index of series to columns in DataFrame.

and you want output as

In this scenario, you can convert the series to DataFrame and call transpose() on the DataFrame to achieve these results.
Let’s see with help of example:

Output:

Pandas series to DataFrame columns

If you want to convert series to DataFrame columns, then you can pass columns=series.
Here is an example:

Output:

As you can see, series(Name, Age and Gender) became columns for DataFrame.
That’s all about How to convert Pandas Series to DataFrame.

Previous
Next

Add Comment