+ 1

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

7th Aug 2019, 3:32 PM
Joseph Ojo
Joseph Ojo - avatar
3 Antworten
+ 3
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?
7th Aug 2019, 3:53 PM
Tibor Santa
Tibor Santa - avatar
+ 1
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
7th Aug 2019, 4:16 PM
Joseph Ojo
Joseph Ojo - avatar
0
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: https://code.sololearn.com/cgnm0t7XIc6s/?ref=app
7th Aug 2019, 10:04 PM
Tibor Santa
Tibor Santa - avatar