简体   繁体   中英

How do I create dictionary from pandas columns based on condition

Currently I am creating dictionary by deleting rows where checker column is false

how can I create s3_range_dict , without deleting rows and just checking whether checker column is true, if it is then add that row's url and name to dictionary

df_s3_range.drop(df_s3_range[df_s3_range['checker'] == False].index, inplace=True)

s3_range_dict = pd.Series(
    df_s3_range.url.values, index=df_s3_range.name).to_dict()
df_s3_range[df_s3_range['checker'] == True].set_index('name')['url'].to_dict()

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