Pandas Series: to_frame() function
Series-to_frame() function
The to_frame() function is used to convert Series to DataFrame.
Syntax:
Series.to_frame(self, name=None)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
name | The passed name should substitute for the series name (if it has one). | object, default None | Required |
Returns: DataFrame
DataFrame representation of Series.
Example:
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series(["p", "q", "r"],
name="vals")
s.to_frame()
Output:
vals 0 p 1 q 2 r
Previous: Series-to_excel() function
Next: Series - to_xarray() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/pandas/series/series-to_frame.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics