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: 
Iterating over a range like that isn't very efficient because once you get past the square root of n, any further tests are redundant.

I found a splendid implementation of a function that derives all factors of a given number [here](https://stackoverflow.com/questions/6800193/what-is-the-most-efficient-way-of-finding-all-the-factors-of-a-number-in-python)

I made a small modification to it and adapted it to this particular problem leading to:

```
from functools import reduce

def factors(n):
    return set(reduce(list.__add__,
                ([i, n//i] for i in range(1, int(n**0.5)+1, n % 2 + 1) if not n % i)))

def sum_divisors(n):
    return sum(factors(n)) - n

print(sum_divisors(102))

```

**Output:**

```
114

```

...and *not* 144 as suggested in the OP's question.

**Credit:**

@agf
When you do

```
for i in range(n ,0 , -1):
if n % i == 0:
  sumlist.append(i)
  n -= 1

```

n is being included.
Thus,

```
print(sum_divisors(3)) # Should sum of 1 = 1

```

will also include the 3 in the check, giving a result greater than what you want.

For some thing closer to what you want:

```
for i in range(n-1,0 , -1):
if n % i == 0:
  sumlist.append(i)
 # n -= 1  This should be removed

```