Can you help give feedback on my US Medical Insurance Costs project? I had a lot of fun doing this project. The most difficult part was setting the objective and the scope of the analysis. I also realized that I need to review basic statistics to really be able to do this right next time.
I had fun creating a class and writing methods. One thing that bugs me though is my search method. I wrote a method that allows me to filter a dictionary of my data using kwargs. I was also able to account for using different comparison operators (<, >, <=, >=, ==, !=) as needed when the kwarg value is an int or a float. While my method works when searching for records with age <= 30 (as an example), it doesn’t allow me to search using 25 <= age <= 30. Inputs on how you’d write that would be great.
rather than use the string module, you could use the _str_ method. I think some functionality of the string module has been deprecated but you didn’t run into any issues so maybe my point is moot. Perhaps it’s a matter of preference.
Thank you @lisalisaj for the feedback and sharing the links. Yes, I was thinking about the float precision, too, and the links you provided were helpful. I’ve made the changes and removed the string module and changed the way I was formatting strings. The only reason why I used it was because I wanted to get a variable with all the letters in the alphabet in the quickest way possible.
Also, in case you know this, is it possible to pass conditions as an argument to a function? In my class search method, the way it is written right now, I’m able to “filter” my data based on key, value and operator. But right now, it only takes 1 operator for a key and float / integer value. Example: charges < 100 or charges > 50. What I want to do is be able to pass 50 < charges < 100 as an argument so I can filter my data based on a range of values, but not quite sure how to implement that. I tried Googling but haven’t found the answer yet.
Or is it possible to loop through a list of conditions, like:
condition_list = ['50 < charges < 100', 'sex == male']
for condition in condition_list:
if condition is True:
pass
Your condition_list consists of two strings so that can’t be evaluated.
Couldn’t you use conditional operators and control flow? Maybe do something like if…then instead?
charges = [100, 75, 23, 55, 96, 77]
for charge in charges:
if charge >=50 and charge <= 100:
print(whatever. or use a return statement here instead)