I am currently working on a problem in which I need to work with binned data. My goal is to get the values of Alpha t1
and Alpha t2
which corresponds to a given Beta value. In this dataframe bellow you can visualize what I mean. Let's say that I have a Beta value of 22.3, then I want to access the Alpha t1 and Alpha t2 out of row 5.
Beta Bins Alpha t1 Alpha t2
1 (0.0, 5.0] 0.0 0.0
2 (5.0, 10.0] 0.0 0.0
3 (10.0, 15.0] 0.0 0.0
4 (15.0, 20.0] 0.0 0.0
5 (20.0, 25.0] 0.0 0.0
6 (25.0, 30.0] 0.0 0.0
7 (30.0, 35.0] 0.0 0.0
8 (35.0, 40.0] 0.0 0.0
9 (40.0, 45.0] 0.0 0.0
10 (45.0, 50.0] 0.0 0.0
11 (50.0, 55.0] 0.0 0.0
12 (55.0, 60.0] 0.0 0.0
13 (60.0, 65.0] 0.0 0.0
14 (65.0, 70.0] 0.0 0.0
So, as I am trying to access this value in a for loop, I have been trying the following:
for i, val in enumerate(Beta):
dfi = df.loc[(df['Beta Bins'] == val)]
However, I am only receiving back an empty dataframe back. I would like to localize the row which corresponds to the interval in which my value is set in. So, is it possible to access that binned data by referencing an specific value?
EDIT
This is how I generate the data:
import numpy as np
import pandas as pd
bins = np.linspace(0,360,73)
alpha0_1 = np.tile(0, len(bins))
alpha0_2 = np.tile(0, len(bins))
df = pd.DataFrame([bins,alpha0_1,alpha0_2]).T
df.columns = ['Beta Bins', 'Alpha 1', 'Alpha 2']
df['Beta Bins'] = pd.cut(df['Beta Bins'], bins)
df = df.dropna()
Hope that I managed to be clear.