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?

mrtpk
  • 1,398
  • 4
  • 18
  • 38
Yousra Gad
  • 363
  • 3
  • 15

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
  • 13,068
  • 19
  • 47
  • 75