Pandas Series To DataFrame β pd.Series.to_frame()
Convert Pandas Series to DataFrame
Pandas offers two main datatypes, Series and DataFrames. They are the building blocks of data analysis within python. You may want to convert a series to a DataFrame and that is where .to_frame() comes in.
Series = Pandas Series is a one-dimensional labeled (it has a name) array which holds data. The axis (think of these as row names) are called index. Simply, a Pandas Series is like an excel column.
DataFrame = A collection of series. Each series name will be the column name.
Pseudo Code: Convert your Pandas Series into a single column Pandas DF
Pandas Series To DataFrame
.to_frame() Parameters
name (Default: None) = By default, the new DF will create a single column with your Series name as the column name. However, if you wanted to change that, you can specify a new name here.
Now the fun part, letβs take a look at a code sample