Код: Выделить всё
id,x,y,z
34295,695.117,74.0177,70.6486
20915,800.784,98.5225,19.3014
30369,870.428,98.742,23.9953
48151,547.681,53.055,174.176
34026,1231.02,73.7678,203.404
34797,782.725,73.9831,218.592
15598,983.502,82.9373,314.081
34076,614.738,86.3301,171.316
20328,889.016,98.9201,13.3068
...
Например, если я разделил на кубы 100 x 100 x 100:
Код: Выделить всё
counts[900][100][100] = 3
Грубый способ создать что-то подобное — создать многоуровневый словарь следующим образом:
Код: Выделить всё
import numpy
import pandas
df = pandas.read_csv("test.csv")
xs = numpy.linspace(0, 1300, 14, endpoint=True)
ys = numpy.linspace(0, 1000, 11, endpoint=True)
zs = numpy.linspace(0, 1000, 11, endpoint=True)
c = {}
for x_index, x in enumerate(xs[:-1]):
c[xs[x_index + 1]] = {}
for y_index, y in enumerate(ys[:-1]):
c[xs[x_index + 1]][ys[y_index + 1]] = {}
for z_index, z in enumerate(zs[:-1]):
c[xs[x_index + 1]][ys[y_index + 1]][zs[z_index + 1]] = df[(df["x"] > xs[x_index]) & (df["x"] ys[y_index]) & (df["y"] zs[z_index]) & (df["z"] 0):
print("c[" + str(xs[x_index + 1]) + "][" + str(ys[y_index + 1]) + "][" + str(zs[z_index + 1]) + "] = " + str(c[xs[x_index + 1]][ys[y_index + 1]][zs[z_index + 1]]))
Код: Выделить всё
c[600.0][100.0][200.0] = 1
c[700.0][100.0][100.0] = 1
c[700.0][100.0][200.0] = 1
c[800.0][100.0][300.0] = 1
c[900.0][100.0][100.0] = 3
c[1000.0][100.0][400.0] = 1
c[1300.0][100.0][300.0] = 1
Подробнее здесь: https://stackoverflow.com/questions/790 ... a-datafram