How to use a list of dictionary In Python
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:
How to Convert a List to a DataFrame Row in Python?
In this article, we will discuss how to convert a list to a dataframe row in Python.
Contact Us