I have a excel spreadsheet that has a table like this:
Variable | bins_edges_list |
---|---|
var1 | [0.998, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 10.0, 14.0, 90.0] |
var2 | [0.999, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 9.0, 11.0, 14.0, 90.0] |
var3 | [-0.001, 1.0, 2.0, 3.0, 4.0, 5.0, 7.0, 83.0] |
I read it into a pandas dataframe using the command
df_bin_edges = pd.read_excel('bin_edges_data_backup.xlsx')
df_bin_edges = df_bin_edges[['Variable','bins_edges_list']]
I tried to extract the bins corresponding to "Variable"
bins_list = df_bin_edges[df_bin_edges['Variable'] == 'var1']['bins_edges_list']
bins_list.replace("'","")
What I expect to see is
bins_list = [0.998, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 10.0, 14.0, 90.0]
but I get the following instead
bins_list = '[0.998, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 10.0, 14.0, 90.0]'
I want to use this bins_list in pd.cut to divide variables into bins.
pd.cut(df[col], bins=bins_list,labels=None, retbins=False, duplicates='drop', precision=0).astype(str)
I get the following error
ValueError: could not convert string to float: '[0.998, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 10.0, 14.0, 90.0]'
Please let me know what I am doing wrong