Home > Software design >  How do I create dictionary from pandas columns based on condition
How do I create dictionary from pandas columns based on condition

Time:01-24

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()

CodePudding user response:

df_s3_range[df_s3_range['checker'] == True].set_index('name')['url'].to_dict()
  •  Tags:  
  • Related