Pandas table help | Sololearn: Learn to code for FREE!


Pandas table help

I have a 52*7 table, the first column contains the restaurant's name while first rows contain the days of the week starting from the second column. ['11', '30', 'am', '9', 'pm'] ['11', '30', 'am', '9', '30', 'pm'] ['11', 'am', '12', '30', 'am'] ['11', 'am', '10', 'pm'] it's filled with values like this, how can I convert it to time

8/7/2019 3:32:08 PM

Joseph Ojo

3 Answers

New Answer


So you mean that am and pm are not always in the same column? So some rows the time has 4 field, 5 fields or 6 fields? If this is the case then you should probably do some data cleansing first, meaning to shift those records to the right where am and pm are in the wrong place. Then you can transform it to time, python has the time library to help with that. What time format do you prefer?


Tibor Santa it's how to clean it, I haven't figured out yet, wrote a function but don't know how to apply it to all the rows. Haven't really worked with time, I just want it to be in time format coz I think if it's time format, I can easily check if a time is between the two points


I am not a big expert on pandas, but I figured out a few basic operations, so this code is working (at least on my pc) and I think it does what you need: