How to use a list with index and columns In Python
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:
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