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

How to combine two lists to dataframe, where one of them will be my columns and another my values?

I had two lists

values = ['98', '42']
columns = ['PREC', 'TEMP']

I want to make something like this:

             PREC            TEMP
0            98               42 

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

>Solution :

The below would work where you pass the values to convert it to dataframe and then use the columns params to assign columns names and then you can override the index with your required index values in the iteration

import pandas as pd
values = ['98', '42']
my_columns = ['PREC', 'TEMP']
my_index = '27/12/2021'

df = pd.DataFrame([values], columns=[my_columns])
df.rename(index={0:my_index},inplace=True)

           PREC    TEMP
27/12/2021  98      42
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