Skip to content
Related Articles

Related Articles

Improve Article
Make a Pandas DataFrame with two-dimensional list | Python
  • Difficulty Level : Medium
  • Last Updated : 24 Oct, 2019

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:




# 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 )

Output:

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

 
Example #2:






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)

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. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :