# Why not work function agregirovaniya NumPy?

Hello!
Pulled from the data base, loaded them into a NumPy array, the function:

`points = np.asarray(rows)`

The resulting array looks somehow so:
[[datetime.date(2016, 10, 7) 150.0]
[datetime.date(2016, 10, 8) 760.0]
...]

Now, I want to aggregate the data from the second column, do this:
`x = points.min(axis=1)`

But I somehow throws this error:

TypeError: '<=' not supported between instances of 'datetime.date' and 'float'

Help, what am I doing wrong?
June 7th 19 at 14:22
June 7th 19 at 14:24
Solution
axis=0
Also issues
TypeError: unsupported operand type(s) for +: 'datetime.date' and 'float'
- Garrison.Armstro commented on June 7th 19 at 14:27
Give code that can be run which does not work. And yet here is this code:

``````# -*- coding: utf-8 -*-

import datetime
import numpy

if __name__ == '__main__':

points = numpy.array([[datetime.date(2016, 10, 7), 150.0],
[datetime.date(2016, 10, 8), 760.0]])

print(points.min(axis=0))``````

Vyvodit to the console exactly what you want:

``````"C:\Program Files\Python 3.6\python.exe" "D:/My Documents/PycharmProjects/tst/tst45.py"
[datetime.date(2016, 10, 7) 150.0]

Process finished with exit code 0``````

Or do you want to choose less date or a real number? - Aubree_Kozey commented on June 7th 19 at 14:30
Here is all my code:

``````import psycopg2
import numpy as np

query = "'SELECT date(a_time) as day, sum(total) FROM all_payment
WHERE point = '13940006'
AND op_type=3
GROUP BY day
ORDER BY day"'

conn = psycopg2.connect("dbname='***' user='***' host='***' password='***'")
cur = conn.cursor()
cur.execute(query)
rows = cur.fetchall()

points = np.full((417,2), rows)
# for row in rows:
# points = np.append(row, points)

points.min(axis=0)``````

The points array has this content:

[[datetime.date(2016, 10, 7) 150.0]
[datetime.date(2016, 10, 8) 760.0]
...]

Aggregation functions for axis=0 is working fine.

But on the second column (axis = 1) aggregation not roll.

Gives this error:
``TypeError: '<=' not supported between instances of 'datetime.date' and 'float'``
- Garrison.Armstro commented on June 7th 19 at 14:33
But on the second column (axis = 1) aggregation not roll.

It is not in the second column, and the second axis. Or direction, or index...

When axis=0 is not in the first post, and on the first direction/index, find the minimum, amount etc. i.e. find the minimum in each column and store the result in a one-dimensional array with length equal to the number of columns in source (for simplicity) 2-dimensional array.

axis=1 is to find the minimum in each row (running along the second index) and store the result in an array with length equal to the number of rows of the original array. Which gives an obvious mistake.

I.e. the minimum of the second column is

`points.min(axis=0)`

Or just

`points.min()`

because 0 is a value axis by default.

PS Your code to run on the execution, obviously, impossible. Well, where do I get the database? - Aubree_Kozey commented on June 7th 19 at 14:36
Thank you very much for your answers! - Garrison.Armstro commented on June 7th 19 at 14:39
unfortunately, the code

`points.sum(axis=0)`

Returns an error:

TypeError: unsupported operand type(s) for +: 'datetime.date' and 'datetime.date'

My task is to summarize the data of the second column. But for some reason does not work. - Garrison.Armstro commented on June 7th 19 at 14:42
Well, Yes, dates can only deduct. Then this:

`points[:, 1].sum()` - Aubree_Kozey commented on June 7th 19 at 14:45
I got it. Thank you. - Garrison.Armstro commented on June 7th 19 at 14:48

Find more questions by tags NumPyPython