Skip to content Skip to sidebar Skip to footer

Store Particular Column Name As Key And Column Data As Values In Dictionary. I Need The Mapping To Be Occur Irrespective Of The Case And Plurality

I have a list Col_values and Data Frame df. Col_values = ['App','dragons'] df apps b c dragon e 1 apple bat cat dance eat 2 air

Solution 1:

df.loc[:,['apps','dragon']].to_dict(orient='list')

Output

{'apps': ['apple', 'air', 'ant', 'alpha', 'axis', 'angry', 'attack'],
 'dragon': ['dance', 'dog', 'doll', 'disc', 'dell', 'None', 'None']}

Solution 2:

try this:

{col:df[col].tolist() for col in df.loc[:,['age','fare']].columns}

Post a Comment for "Store Particular Column Name As Key And Column Data As Values In Dictionary. I Need The Mapping To Be Occur Irrespective Of The Case And Plurality"