Good day.
If someone can help me, I have a list in a CVS file like the following.
Out[4]:
_usuarios,Estrato_A1,Estrato_A,Estrato_B,Estrato_C,Estrato_D
1 , 6.86 , 5.43 , 4.30 , 3.53 , 2.73
2 , 10.97 , 8.68 , 6.88 , 5.65 , 4.37
3 , 15.08 , 11.93 , 9.46 , 7.76 , 6.00
4 , 19.20 , 15.19 , 12.04 , 9.88 , 7.64
5 , 23.15 , 18.31 , 14.51 , 11.91 , 9.21
Where my input can be _usuarios = 4
and Estrato = C
, and I need it to return the value of 9.88
.
This is another example I was trying to run.
import numpy as np
Factor_M = pd.read_csv(r'D:\Factor_M.csv')
Out[27]:
Nro._de_usuarios ,Factor_M
5 , 9.49
6 , 10.80
7 , 12.10
8 , 13.50
9 , 14.80
def find_nearest(Factor_M,value):
idx = (np.abs(Factor_M-value)).argmin()
return Factor_M[idx]
value = 21
print(find_nearest(Factor_M, value))
What you could do is store the content of the CVS file in a list, in such a way that the rows are the different users, and each column of the row could be the different strata with their corresponding identifier in the first position. More or less you would have something like this:
Then, any operation, whether it is data query of a certain user and a stratum, would be simpler(?