How to use T function 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 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:
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