Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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’]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

my table has three rows and two columns
i need your help

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading