October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

Ways to Convert a Pandas Series to a DataFrame in Python

Use to_frame() to keep a Series index, reset_index() to make index labels columns, or unstack() to pivot a MultiIndex level.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use s.to_frame() to turn a pandas Series into a one-column DataFrame while keeping its index as the row index. Use s.reset_index() when the Series index labels should instead become ordinary DataFrame columns. For a MultiIndex Series, choose reset_index() to expose index levels or unstack() to pivot one level into columns.

Choose based on what should happen to the Series index

Goal Method Result
Keep the current index as the DataFrame row index s.to_frame() One data column; its label defaults to the Series name when available.
Set a specific label for the values column s.to_frame(name="values") One data column named values, with the Series index retained.
Make index labels into DataFrame columns s.reset_index() Index-level column(s), followed by a column containing Series values.
Make index labels into columns and name the values column s.reset_index(name="values") Former index column(s) plus a values column named values.
Spread one MultiIndex level across columns s.unstack() A pivoted DataFrame; the resulting layout depends on the levels.

Keep the Series index with to_frame()

For a straightforward one-column conversion, use the Series to_frame() method:

import pandas as pd

s = pd.Series([10, 20, 30], index=["a", "b", "c"], name="score")
df = s.to_frame()

The resulting DataFrame has one column, named score, and keeps a, b, and c as its row index. The pandas API describes Series.to_frame as converting a Series to a DataFrame and returning a DataFrame representation: pandas Series.to_frame API.

Set or override the column name

Pass name when the Series is unnamed or you want a deliberate output label:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
df = s.to_frame(name="values")

This sets the one DataFrame column’s label to values, overriding the Series name if it has one.

Turn index labels into columns with reset_index()

If the index labels are data you need in the result, use reset_index() with its default drop=False behavior:

df = s.reset_index()

The old index becomes a DataFrame column, and another column contains the Series values. If the index is named, that name is used for its column; otherwise pandas supplies a default label. The official API documents the parameters and return behavior: pandas Series.reset_index API.

Name the values column

Use the name argument to label the column containing the Series values:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
df = s.reset_index(name="values")

Here, name applies to the values column, not the column created from the old index.

Do not use drop=True when you need a DataFrame

s.reset_index(drop=True) discards the old index without inserting it into the result and returns a Series rather than a DataFrame. Leave drop at its default when you want the old index retained as a column and a DataFrame returned.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Handle a Series with a MultiIndex

A MultiIndex has multiple index levels, so the right operation depends on whether you want those levels as columns or want to reshape the data.

Expose index levels as columns

Call reset_index() to move all MultiIndex levels into columns alongside the values. To reset only selected levels and leave some index structure in place, pass the relevant level or levels with level=.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pivot a level into columns with unstack()

Use s.unstack() when the intended result spreads one MultiIndex level across the DataFrame’s columns, rather than listing every index level as a column. The pandas Series API includes unstack as a way to produce a DataFrame from a Series with a MultiIndex: pandas Series API.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.