How to Convert a List to a DataFrame Row in Python?

28 Dec, 2021
In this article, we will discuss how to convert a list to a dataframe row in Python.
This is known as the Transpose function, this will convert the list into a row. Here each value is stored in one column.
Syntax: pandas.DataFrame(list).T
Example:
Python3
# import pandas moduleimport pandas as pd # consider a listlist1 = ["durga", "ramya", "meghana", "mansa"] # convert the list into dataframe rowdata = pd.DataFrame(list1).T # add columnsdata.columns = ['student1', 'student2',                'student3', 'student4'] # displaydata
Output:
Here we are converting a list of lists to dataframe rows
Syntax: pd.DataFrame(list)
where list is the list of lists
Example:
Python3
# import pandas moduleimport pandas as pd # consider a listlist1 = [["durga", "java", 90], ["gopi", "python", 80],         ["pavani", "c/cpp", 94], ["sravya", "html", 90]] # convert the list into dataframe rowdata = pd.DataFrame(list1) # add columnsdata.columns = ['student1', 'subject', 'marks'] # displaydata
Output:
Here we are getting data (rows ) from the list and assigning columns to these values from columns 
Syntax: pd.DataFrame(list, columns, dtype )
where
list is  the list of input values
columns are the column names for list of values
dtype is the column data type
Example:
Python3
# import pandas moduleimport pandas as pd # consider a listlist1 = [["durga", "java", 90], ["gopi", "python", 80],         ["pavani", "c/cpp", 94], ["sravya", "html", 90]] # convert the list into dataframe row by adding columnsdata = pd.DataFrame(list1, columns=['student1',                                    'subject',                                    'marks'])  # displaydata
Output:
Here  we are taking separate lists as input such that each list will act as one column, so the number of lists = n columns in the dataframe, and using zip function we are combining the lists.
Syntax pd.DataFrame(list(zip(list1,list2,.,list n)),columns)
where
columns is the column for the list values
list1.list n represent number of input lists for columns
Example:
Python3
# import pandas moduleimport pandas as pd # consider a listlist1 = ["durga", "ramya", "sravya"]list2 = ["java", "php", "mysql"]list3 = [67, 89, 65] # convert the list into dataframe row by# using zip()data = pd.DataFrame(list(zip(list1, list2, list3)),                    columns=['student', 'subject', 'marks'])  # displaydata
Output:
Here we are passing the individual lists which act as columns in the data frame to keys to the dictionary, so by passing the dictionary into dataframe() we can convert list to dataframe.
Syntax: pd.DataFrame{‘key’: list1, ‘key’: list2, ........,’key’: listn}
These keys will be the column names in the dataframe.
Example:
Python3
# import pandas moduleimport pandas as pd # consider a listlist1 = ["durga", "ramya", "sravya"] list2 = ["java", "php", "mysql"] list3 = [67, 89, 65] # convert the list into dataframe row by# using dictionarydictionary = {'name': list1, 'subject': list2,              'marks': list3} data = pd.DataFrame(dictionary) # displaydata
Output:
Here we are taking input from multi-dimensional lists and assigning column names in the DataFrame() function
Syntax: pd.DataFrame(list,columns)
where
list is an multidimensional listcolumns are the column names
list is an multidimensional list
columns are the column names
Example:
Python3
# import pandas moduleimport pandas as pd # consider a listlist1 = [["durga", "java", 90],         ["gopi", "python", 80],         ["pavani", "c/cpp", 94],         ["sravya", "html", 90]] # convert the list into dataframe# row using columns from multi listsdata = pd.DataFrame(list1, columns=['student1',                                    'subject',                                    'marks']) # displaydata
Output:
kk773572498
pandas-dataframe-program
Picked
Python pandas-dataFrame
Python-pandas
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
How to drop one or multiple columns in Pandas Dataframe
Python | os.path.join() method
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
Python | Get unique values from a list
Create a directory in Python