0

I have an excel file which contains 2 columns and I want to convert these columns to the dictionary using the header as key and rows as values.

file1.xlxs

name      price
Merry     5000
John      6500
Nat       4800

The dictionary should be like this:

List1 =  {'name':['Merry,John,Nat'],'price':['5000,6500,4800']}

Please help?

tpk
  • 1,228
  • 4
  • 16
  • 32
Yousra Gad
  • 365
  • 3
  • 14
  • 1
    Is that what they're calling a dictionary now-a-days? –  Oct 17 '18 at 07:10
  • Using Pandas we can do it. Check out this answer-https://stackoverflow.com/a/16896091/6561141 – tpk Oct 17 '18 at 07:10

1 Answers1

0

Use pandas library for this

import pandas as pd

df = pd.read_excel("path to your excel file")

list1 = df.to_dict(orient='list')

Here is documentation for df.to_dict

Sociopath
  • 12,395
  • 17
  • 43
  • 69