bbartling
bbartling

Reputation: 3502

panda read xlsx file datetime issue

I am attempting to read an excel file and parse the contents into a Python dictionary.

from pandas import *

xls = ExcelFile('vavs.xlsx')
data = xls.parse(xls.sheet_names[0])
print(data.to_dict())

The problem that I am running into is a format of one of the cells inside the excel file. This column represents a network & address information and Excel thinks this is a time, like 11:01 AM

enter image description here

What I am attempting to use this for I need the formatting 11:01 to be as is.. When I print the dictionary in Python it comes thru with an unwanted datetime.time and I only want a string 11:01

 'trunkAddress': {0: datetime.time(11, 1),
  1: datetime.time(11, 2),
  2: datetime.time(11, 3),
  3: datetime.time(11, 4),
  4: datetime.time(11, 5),
  5: datetime.time(11, 6),
  6: datetime.time(11, 16),
  7: datetime.time(11, 17),
  8: datetime.time(11, 18)},

Is there a way around this? Like converting the Excel file to a csv and then reading the data into Python? This is a small excel file for testing purposes, for whatever its worth I have the file in my git account here.

Thanks for tips

Upvotes: 0

Views: 136

Answers (1)

Juan C
Juan C

Reputation: 6132

Something like this should do:

df = pd.read_excel('your_table.xlsx', dtype={'trunkAdress':str}

Upvotes: 3

Related Questions