Question: I have a data frame with the following properties:

```
    Column   Non-Null Count   Dtype 
---  ------   --------------   ----- 
 0   Date     226611 non-null  object

 1   Time     226611 non-null  object

 2   Code     226611 non-null  object

 3   Message  226611 non-null  object

```

`Date` column has values as format : `2021-11-28 00:00:00` and `Time` column has values as format: `08:15:12.476000`. I am trying to create a `DateTime` column with the following code (basically tried most of the available pandas' methods like to\_datetime, to\_timestampe, etc.):

```
df["DateTime"] = pd.to_datetime(df["Date"]+" "+df["Time"])

```

but I keep getting the following error: `unsupported operand type(s) for +: 'datetime.datetime' and 'str'`. Can someone point out what am I missing here? The expected output would be (restricting milliseconds to 2 digits only):

```
     Date                  Time               DateTime 

 0   2021-11-28 00:00:00   08:15:12.476000    2021-11-28 08:15:12.47

```

Answer: 
Two problems:

* `n -= 1` is wrong and ultimately leads to i and n always being equal, therefore `n % i == 0` always being true (therefore the large numbers you get) => delete this line
* `i` shouldn't start from `n`, since based on your expected results you don't want the number itself to be included in the sum of divisors. Therefore: `range(n - 1, 0, -1)` insteaf of `range(n ,0 , -1)`

Apart from this, your code has some unnecessary parts, like the `elif`. Consider GGberry's version for a cleaner style.

---

Or use a generator expression instead of the loops:

```
def sum_divisors(n):
    return sum(i for i in range(1, n) if not n % i)

```
As always when you work with divisors, you can speed up things a lot by just looping up to the square root of `n`. When you find a divisor `i` lower than the square root you know `n // i` is a divisor too.

This leaves us with some special cases to handle - especially so since you want to consider `1` as a divisor while not considering `n` itself. See this code:

```
def sum_divisors_sqrt(n):
    if n < 1:
        return 0
    sum_divs = [1]
    sqrt_n = int(sqrt(n))
    if n % sqrt_n == 0:
        sum_divs.append(sqrt_n)
    for i in range(2, sqrt_n):
        if n % i == 0:
            sum_divs.append(i)
            sum_divs.append(n//i)
    return sum(sum_divs)

```

On my PC this is 20x faster for `n = 1000`, 90x faster for `n = 10000`