TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Pandas Series.to_frame()

Pandas Series.to_frame() with What is Python Pandas, Reading Multiple Files, Null values, Multiple index, Application, Application Basics, Resampling, Plotting the data, Moving windows functions, Series, Read the file, Data operations, Filter Data etc.

<< Back to PANDAS

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.

Syntax

Series.to_frame(name=None)

Parameters

name: Refers to the object. Its Default value is None. If it has one value, the passed name will be substituted for the series name.

Returns

It returns DataFrame representation of Series.

Example1

s = pd.Series(["a", "b", "c"],
name="vals")
s.to_frame()

Output

       vals
0          a
1          b
2          c

Example2

import 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()




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf