Read from Excel and convert the output to dictionary in Python

by Srinivas G   Last Updated October 28, 2018 14:22 PM

import os
import datetime
import pandas as pd
import xlrd
df = pd.read_excel("m2.xlsx")
print(df)
    Date            05:00 A.M         06:00A.M
23-09-2018           8                   1                
24-09-2018           3                   4 

My out put should be:

{'Date':['23-08-2018','24-08-2018'],'05:00 A.M':[8,3],'06:00 A.M':[1,4]}

What I have done:

import os
import datetime
import pandas as pd
import xlrd
import numpy as np
df = pd.read_excel("m2.xlsx",index_col=0).to_dict()
print(df)
Tags : python pandas


Related Questions


Updated August 05, 2018 15:22 PM

Updated August 28, 2017 12:22 PM

Updated June 19, 2018 15:22 PM

Updated May 13, 2015 21:09 PM

Updated February 29, 2016 01:09 AM