Python list to matrix(numpy, pandas Dataframe)

 list → matrix (np.reshape)

1_list = list(2 * data for data in range(0, 25)) 2_list




 


1import numpy as np 2_vals = np.reshape(_list, (5,5)) 3_vals




 

1import pandas as pd 2df = pd.DataFrame(_vals) 3df


 


1column_name = ['col_0', 'col_1','col_2','col_3','col_4'] 2df = pd.DataFrame(_vals, columns=column_name) 3df

 



1index_name = ['ind_0', 'ind_1','ind_2','ind_3','ind_4'] 2df = pd.DataFrame(_vals, columns=column_name, index=index_name)







0 댓글