How to create pandas DataFrame from numpy array in Python

2 Answers

0 votes
import numpy as np 
import pandas as pd 
  
array = np.array([['1', '2'], ['3', '4'], ['5', '6']]) 
  
dataFrame = pd.DataFrame(array, columns = ['col1', 'col2']) 

print(dataFrame) 

    
            
       
'''
run:
   
  col1 col2
0    1    2
1    3    4
2    5    6
             
'''

 



answered May 13, 2020 by avibootz
0 votes
import numpy as np 
import pandas as pd 
  
array = np.array([['1', '2'], ['3', '4'], ['5', '6']]) 
  
dataFrame = pd.DataFrame(data=array, index=["row1", "row2", "row3"], columns=["col1", "col2"])

print(dataFrame) 

    
            
       
'''
run:
   
     col1 col2
row1    1    2
row2    3    4
row3    5    6
             
'''

 



answered May 13, 2020 by avibootz

Related questions

3 answers 286 views
1 answer 161 views
2 answers 223 views
1 answer 225 views
1 answer 210 views
1 answer 167 views
167 views asked May 14, 2020 by avibootz
1 answer 172 views
...