简体   繁体   中英

Initialising a pandas dataframe with column names defined by a list

I want to initilise a pandas dataframe with 1613 rows. I want to define the column names by the list 'indicns_list' (which has 471 elements). I tried this:

con_meds3 = pd.DataFrame(np.nan, index=range(0,1613),columns=indicns_list)

But I'm getting this error:

ValueError: Shape of passed values is (1613, 471), indices imply (1613, 1)

help! :)

their is issue in the indicns_list if below code does fine. try this

con_meds3 = pd.DataFrame(np.nan, index=range(0,1613),columns=[i for i in range(1613)])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM