Data Science Porfolio Project US Medical Costs

here is my code for the us medical costs project.
I largely used pandas built in function to do some basic comparisons…was having issues trying to parse through the variables in bmi to create a variable that would cull a new dataframe for all indexes with a bmi greater than or equal to 25.0 and less than 30.

next up is try try and parse and find correlation between data to see why SE region had the highest average insurance costs. and move on to data visualiztion

feedback is welcome

You could always use the .describe() method on the df or on a specific column in the df to get descriptive stats.
ex:

southwest['bmi'].describe()

count    325.000000
mean      30.596615
std        5.691836
min       17.400000
25%       26.900000
50%       30.300000
75%       34.600000
max       47.600000
Name: bmi, dtype: float64

And, since you’ve broken out the df into regions, you could use .iloc() with .values() to find those with bmi (or age or whatever) that’s >= to whatever number you’re looking for.

Ex:

southwest_highbmi = southwest.iloc[(southwest['bmi']>=25).values]
print(southwest_highbmi)

Output:
     age     sex   bmi  children smoker     region      charges
0      19  female  27.9         0    yes  southwest  16884.92400
12     23    male  34.4         0     no  southwest   1826.84300
18     56    male  40.3         0     no  southwest  10602.38500
19     30    male  35.3         0    yes  southwest  36837.46700
21     30  female  32.4         1     no  southwest   4149.73600
...   ...     ...   ...       ...    ...        ...          ...
1313   19  female  34.7         2    yes  southwest  36397.57600
1329   52    male  38.6         2     no  southwest  10325.20600
...

See:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.describe.html

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iloc.html

Thanks, just updated the code with the correct way to bracket the bmi so I could do check for both overweight and obese based on bmi

1 Like