My problem is kind of simple, but I'm not sure there's a way to do what I'm looking for:
I had to store in a SQL database some data, that includes some intervals that will later be used. Because of this, I had to store it as a string, like this:
variable interval
A (-0.001, 2.0]
A (2.0, 6.0]
So, then, I want to use said intervals to cut another variable, like this:
df1 = pd.DataFrame({'interval': {4: '(-0.001, 2.0]',
5: '(2.0, 6.0]'},
'variable': {4: 'A',
5: 'A',
}})
df2 = pd.DataFrame({'A': [1,1,3]})
bins = df1[df1.variable.eq('A')].interval
new_series = pd.cut(df2['A'], bins=bins)
But this brings:
ValueError: could not convert string to float: '(-0.001, 2.0]'
Tried:
bins = bins.astype('interval')
But this brings:
TypeError: type <class 'str'> with value (-0.001, 2.0] is not an interval
Is there something I can do? Thanks