user16431323
user16431323

Reputation:

Create Table with two lists python

I have two lists. I have a list of table titles(title_df). My other list is from my contents (prediction_df) to be sorted by titles. I want to populate my contents by titles and create a table in the result.

title_df=['a','b']

prediction_df=['1','2','3','800800','802100','800905']

My table has three rows and two columns

Upvotes: 1

Views: 793

Answers (1)

jezrael
jezrael

Reputation: 863166

Use numpy.reshape, 2 is for 2 columns and -1 is for count number of rows by data, last pass to DataFrame constructor:

df = pd.DataFrame(np.reshape(prediction_df, (-1,2), order='F'), columns=title_df)
print (df)
   a       b
0  1  800800
1  2  802100
2  3  800905

Upvotes: 2

Related Questions