close

How to convert list to row dataframe with Pandas

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to convert list to row dataframe with Pandas in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to convert list to row dataframe with Pandas?

  1. How to convert list to row dataframe with Pandas?

    This is somewhat peripheral to your particular issue, but I figured I would post it in case it helps someone else out.

  2. convert list to row dataframe with Pandas

    This is somewhat peripheral to your particular issue, but I figured I would post it in case it helps someone else out.

Method 1

You can use:

df = pd.DataFrame([A])
print (df)
   0  1  2    3 4
0  1  d  p  bab  

If all values are strings:

df = pd.DataFrame(np.array(A).reshape(-1,len(A)))
print (df)

   0  1  2    3 4
0  1  d  p  bab  

Thank you AKS:

df = pd.DataFrame(A).T
print (df)
   0  1  2    3 4
0  1  d  p  bab  

Method 2

This is somewhat peripheral to your particular issue, but I figured I would post it in case it helps someone else out.

To convert a list of lists (and give each column a name), just pass the list to the data attribute (along with your desired column names) when instantiating the new dataframe, like so:

my_python_list = [['foo1', 'bar1'],
                  ['foo2', 'bar2']]
new_df = pd.DataFrame(columns=['my_column_name_1', 'my_column_name_2'], data=my_python_list)

result:

  my_column_name_1 my_column_name_2
0             foo1             bar1
1             foo2             bar2

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read