How to Convert a List to a DataFrame Row in Python?
Last Updated :
28 Dec, 2021
In this article, we will discuss how to convert a list to a dataframe row in Python.
Method 1: Using T function
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 module
import pandas as pd
# consider a list
list1 = ["durga", "ramya", "meghana", "mansa"]
# convert the list into dataframe row
data = pd.DataFrame(list1).T
# add columns
data.columns = ['student1', 'student2',
'student3', 'student4']
# display
data
Output:

Method 2: Creating from multi-dimensional list to dataframe row
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 module
import pandas as pd
# consider a list
list1 = [["durga", "java", 90], ["gopi", "python", 80],
["pavani", "c/cpp", 94], ["sravya", "html", 90]]
# convert the list into dataframe row
data = pd.DataFrame(list1)
# add columns
data.columns = ['student1', 'subject', 'marks']
# display
data
Output:

Method 3: Using a list with index and columns
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 module
import pandas as pd
# consider a list
list1 = [["durga", "java", 90], ["gopi", "python", 80],
["pavani", "c/cpp", 94], ["sravya", "html", 90]]
# convert the list into dataframe row by adding columns
data = pd.DataFrame(list1, columns=['student1',
'subject',
'marks'])
# display
data
Output:

Method 4: Using zip() function
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 module
import pandas as pd
# consider a list
list1 = ["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'])
# display
data
Output:

Method 5: Using a list of dictionary
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 module
import pandas as pd
# consider a list
list1 = ["durga", "ramya", "sravya"]
list2 = ["java", "php", "mysql"]
list3 = [67, 89, 65]
# convert the list into dataframe row by
# using dictionary
dictionary = {'name': list1, 'subject': list2,
'marks': list3}
data = pd.DataFrame(dictionary)
# display
data
Output:

Method 6: Creating from multi-dimensional list to dataframe row with columns
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 list
- columns are the column names
Example:
Python3
# import pandas module
import pandas as pd
# consider a list
list1 = [["durga", "java", 90],
["gopi", "python", 80],
["pavani", "c/cpp", 94],
["sravya", "html", 90]]
# convert the list into dataframe
# row using columns from multi lists
data = pd.DataFrame(list1, columns=['student1',
'subject',
'marks'])
# display
data
Output:
Similar Reads
How to Convert a List to a Dataframe in R We have a list of values and if we want to Convert a List to a Dataframe within it, we can use a as.data.frame. it Convert a List to a Dataframe for each value. A DataFrame is a two-dimensional tabular data structure that can store different types of data. Various functions and packages, such as dat
4 min read
How to Convert Pandas DataFrame into a List? In this article, we will explore the process of converting a Pandas DataFrame into a List, We'll delve into the methods and techniques involved in this conversion, shedding light on the versatility and capabilities of Pandas for handling data structures in Python.Ways to convert Pandas DataFrame Int
7 min read
How to append a list as a row to a Pandas DataFrame in Python? Prerequisite: Pandas DataFrame In this article, We are going to see how to append a list as a row to a pandas dataframe in Python. It can be done in three ways: Using loc[]Using iloc[]Using append()Append list using loc[] methods Pandas DataFrame.loc attribute access a group of rows and columns by l
3 min read
How to Convert String to Integer in Pandas DataFrame? Let's see methods to convert string to an integer in Pandas DataFrame: Method 1: Use of Series.astype() method. Syntax: Series.astype(dtype, copy=True, errors=âraiseâ) Parameters: This method will take following parameters: dtype: Data type to convert the series into. (for example str, float, int).c
3 min read
Convert dataframe to nested list in R In R Programming Data frame is nothing but a two-dimensional entity that consists of rows and columns whereas Lists in R are data structures that are able to store multiple data values at once. List Creation Lists in R can be created using list() function. Syntax: list(element1, element2, element3,.
2 min read
How to Convert Pandas to PySpark DataFrame ? In this article, we will learn How to Convert Pandas to PySpark DataFrame. Sometimes we will get csv, xlsx, etc. format data, and we have to store it in PySpark DataFrame and that can be done by loading data in Pandas then converted PySpark DataFrame. For conversion, we pass the Pandas dataframe int
3 min read
How to Convert Integers to Strings in Pandas DataFrame? In this article, we'll look at different methods to convert an integer into a string in a Pandas dataframe. In Pandas, there are different functions that we can use to achieve this task : map(str)astype(str)apply(str)applymap(str) Example 1 : In this example, we'll convert each value of a column of
3 min read
How to convert pandas DataFrame into JSON in Python? We are given a pandas DataFrame, and our task is to convert it into JSON format using different orientations and custom options. JSON (JavaScript Object Notation) is a lightweight, human-readable format used for data exchange. With Pandas, this can be done easily using the to_json() method. For exam
4 min read
How to Convert Index to Column in Pandas Dataframe? Pandas is a powerful tool which is used for data analysis and is built on top of the python library. The Pandas library enables users to create and manipulate dataframes (Tables of data) and time series effectively and efficiently. These dataframes can be used for training and testing machine learni
2 min read
Create a list from rows in Pandas DataFrame | Set 2 In an earlier post, we had discussed some approaches to extract the rows of the dataframe as a Python's list. In this post, we will see some more methods to achieve that goal. Note : For link to the CSV file used in the code, click here. Solution #1: In order to access the data of each row of the Pa
2 min read