Make a Pandas DataFrame with two-dimensional list | Python

As we know Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier.

Pandas Dataframe can be achieved in multiple ways. In this article, we will learn how to create a dataframe using two-dimensional List.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# import pandas as pd 
import pandas as pd  
      
# List1  
lst = [['Geek', 25], ['is', 30], 
       ['for', 26], ['Geeksforgeeks', 22]] 
  
# creating df object with columns specified    
df = pd.DataFrame(lst, columns =['Tag', 'number']) 
print(df )

chevron_right


Output:

             Tag  number
0           Geek      25
1             is      30
2            for      26
3  Geeksforgeeks      22

 
Example #2:



filter_none

edit
close

play_arrow

link
brightness_4
code

import pandas as pd  
      
# List1  
lst = [['tom', 'reacher', 25], ['krish', 'pete', 30], 
       ['nick', 'wilson', 26], ['juli', 'williams', 22]] 
      
df = pd.DataFrame(lst, columns =['FName', 'LName', 'Age'],
                                           dtype = float
print(df)

chevron_right


Output:

   FName     LName  Age
0    tom   reacher   25
1  krish      pete   30
2   nick    wilson   26
3   juli  williams   22

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.