Medical visualiser error code

Here is my code it does create the 2 maps as requested but I do get the following error and not sure where or what it means can someone help.

here is the error.
 python
Matplotlib created a temporary config/cache directory at /tmp/matplotlib-09zxtysk because the default path (/config/matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.
Traceback (most recent call last):
File “”, line 6, in
TypeError: draw_cat_plot() missing 1 required positional argument: ‘df’
exit status 1

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

# Import data
df = pd.read_csv("medical_examination.csv")

# Add 'overweight' column
def bmi(df):

    weight = df['weight']
    height = df['height']/100
    bmi = weight/(height**2)
    if bmi > 25:
        return 1
        return 0

df['overweight'] = df.apply(bmi,axis=1)

# Normalize data by making 0 always good and 1 always bad. If the value of 'cholesterol' or 'gluc' is 1, make the value 0. If the value is more than 1, make the value 1.
def cholestrol(df):

    if df['cholesterol'] > 1:
        return 1
        return 0

df["cholesterol"] = df.apply(cholestrol, axis=1)

def gluc(df):

    if df["gluc"] >1:
        return 1
        return 0

df['gluc'] = df.apply(gluc, axis=1)

# Draw Categorical Plot
def draw_cat_plot(df):

    # Create DataFrame for cat plot using `pd.melt` using just the values from 'cholesterol', 'gluc', 'smoke', 'alco', 'active', and 'overweight'.
    df_cat = df[['cholesterol', 'gluc', 'smoke', 'alco', 'active','overweight', 'cardio']]
    melt_new = pd.melt(df_cat, id_vars='cardio').value_counts()
    # Group and reformat the data to split it by 'cardio'. Show the counts of each feature. You will have to rename one of the columns for the catplot to work correctly.
    df_melt = melt_new.groupby(['cardio', 'variable', 'value']).sum().reset_index(name='total')

    #fig, ax = plt.subplots(figsize=(9,9))
    # Draw the catplot with 'sns.catplot()'
    fig = sns.catplot(x='variable', y= 'total', hue='value', col='cardio', aspect=0.4, data=df_melt, kind='bar')

    # Do not modify the next two lines
    return fig

# Draw Heat Map
def draw_heat_map(df):

    # Clean the data
    df= df[df['ap_lo']<=df['ap_hi']]

    height_0025 = df['height'].quantile(0.025)
    height_0975 = df['height'].quantile(0.975)
    weight_0025 = df['weight'].quantile(0.025)
    weight_0975 = df['weight'].quantile(0.975)
    df_heat = df[((df['height'] >=height_0025) & (df['height']<= height_0975)&(df['weight'] >=weight_0025) & (df['weight']<= weight_0975))]

    # Calculate the correlation matrix
    corr = df_heat.corr()

    # Generate a mask for the upper triangle
    mask =  np.zeros_like(corr)
    mask[np.triu_indices_from(mask)] = True

    # Set up the matplotlib figure
    fig,ax = plt.subplots()
    # Draw the heatmap with 'sns.heatmap()'

    ax = sns.heatmap(corr, mask=mask, annot=True, annot_kws={'size':10},fmt='.1f')

        # Do not modify the next two lines
    return fig


draw_cat_plot and draw_heat_map functions are not expected to accept arguments. Signature of these functions were changed to require df parameter, but the way they are called in and during testing doesn’t use argument.

Thanks for the response but still not sure what to do.

Don’t use arguments when building the functions.

many thanks I got it to work

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.