Skip to content Skip to sidebar Skip to footer

Pandas: Need To Count The Number Of Values Of A Column Between 0 And 0.001 Then 0.001 And 0.002 Etc

My code so far looks like this: conn = psycopg2.connect('dbname=monty user=postgres host=localhost password=postgres') cur = conn.cursor() cur.execute('SELECT * FROM binance.zrxeth

Solution 1:

For consistently separated groups, you can use floor division to construct a grouper:

np.random.seed(0)

df = pd.DataFrame({'A': np.random.random(100) * 0.5})

step = 0.05
res = df.groupby(df['A'] // step).size()
res.index *= step

print(res)

A
0.00    12
0.05    13
0.10     9
0.15     7
0.20    10
0.25    11
0.30    15
0.35     8
0.40     6
0.45     9
dtype: int64

Post a Comment for "Pandas: Need To Count The Number Of Values Of A Column Between 0 And 0.001 Then 0.001 And 0.002 Etc"