C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Pandas Series.to_frame()Series is defined as a type of list that can hold an integer, string, double values, etc. It returns an object in the form of a list that has an index starting from 0 to n where n represents the length of values in Series. The main difference between Series and Data Frame is that Series can only contain a single list with a particular index, whereas the DataFrame is a combination of more than one series that can analyze the data. The Pandas Series.to_frame() function is used to convert the series object to the DataFrame. SyntaxSeries.to_frame(name=None) Parametersname: Refers to the object. Its Default value is None. If it has one value, the passed name will be substituted for the series name. ReturnsIt returns DataFrame representation of Series. Example1s = pd.Series(["a", "b", "c"], name="vals") s.to_frame() Output vals 0 a 1 b 2 c Example2import pandas as pd import matplotlib.pyplot as plt emp = ['Parker', 'John', 'Smith', 'William'] id = [102, 107, 109, 114] emp_series = pd.Series(emp) id_series = pd.Series(id) frame = { 'Emp': emp_series, 'ID': id_series } result = pd.DataFrame(frame) print(result) Output Emp ID 0 Parker 102 1 John 107 2 Smith 109 3 William 114
Next TopicSeries.unique()
|