tchakravarty - 6 months ago 19

Python Question

I have a

`pandas.Series`

`Series`

Here is one way to do it, that requires two type conversions:

`import pandas as pd`

days_hours = pd.Series(npr.randint(low=1e4, high=99999, size=1000))

days = days_hours.astype('str').str.slice(start=0, stop=3).astype('int64')

hours = days_hours.astype('str').str.slice(start=3, stop=5).astype('int64')

This is very time-consuming given that on average my

`Series`

`Series`

I tried an alternate solution which involved

`apply`

`lambda`

`Series`

Answer

It will be much quicker to do these operations arithmetically using integer division and the modulo operator:

```
days = days_hours // 100
hours = days_hours % 100
```