Medical Data Visualizer - Seaborne ValueError

Hello,

When trying to run my code in GitPod I receive a ValueError for my y-axis value on the first figure. The problem seems to stem from Seaborn being unable to interpret my “total” column. I have attached a picture of my error below. I ran this exact code within VSCode and it outputs fine with no errors given.

Is there something incorrect about the way I went about renaming the column ? Or is the error something else?

I am using google chrome as my browser.

Please link to your gitpod?

This is the URL to my code. I am not used to GitPod so if this doesn’t work please let me know.

No problem, me too. This was just the link to the github boilerplate.

Okay, I was able to find the guide for setting up a repo. I made a branch with my changes. The link to my github code is below. Please let me know if this works.

You’re not able to link directly to the gitpod project?

This is just a fork of the boilerplate, it’s empty:

# Import data
df = None

# Add 'overweight' column
df['overweight'] = None

# 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.


# Draw Categorical Plot
def draw_cat_plot():
    # Create DataFrame for cat plot using `pd.melt` using just the values from 'cholesterol', 'gluc', 'smoke', 'alco', 'active', and 'overweight'.
    df_cat = None


    # Group and reformat the data to

You have to select the dropdown arrow switch to “feat/medical_data_visualizer-solution” (image below).

image

Here is the link to the GitPod workspace I have opened in my browser, but this did not work last time I tried.

https://freecodecam-boilerplate-syuts4ufrmb.ws-us108.gitpod.io/

Did that link work? Please let me know if there is a guide somewhere on how to correctly share the code. Again, I apologize for all the trouble with this post.

No problem gitpod is new for me too.

Try one of these options if you click the hamburger menu in the top left:

Screenshot 2024-02-21 182020

It will generate a link in the lower right:

Screenshot 2024-02-21 181942

Here is the link to my “Running Workspace”

https://freecodecam-boilerplate-syuts4ufrmb.ws-us108.gitpod.io

1 Like

It was working but now it seems to have timed out.

Add a print line right before your sns.catplot like this:

  print(df_cat)
  fig = sns.catplot(data=df_cat

it should look like this:

    cardio     variable  value  total
0        0       active      0   6378
1        0       active      1  28643
2        0         alco      0  33080
3        0         alco      1   1941
4        0  cholesterol      0  29330
5        0  cholesterol      1   5691
6        0         gluc      0  30894
7        0         gluc      1   4127
8        0   overweight      0  15915
9        0   overweight      1  19106
10       0        smoke      0  31781
11       0        smoke      1   3240
12       1       active      0   7361
13       1       active      1  27618
14       1         alco      0  33156
15       1         alco      1   1823
       1        smoke      1   2929
...

My result is different.

Here is my result from running the code on GitPod. It makes sense that can’t find the totals column since it is labeled “0” here.

However, here is my result running the same code using VScode (which is where I do all of my coding prior to copying it to GitPod). The code is the exact same between the two so I don’t know why it works locally on my PC but not in GitPod.

Here is a link to a “snapshot” of my workspace. If I am correct you should be able to open your own fresh copy of my workspace that is not linked and make any changes you deem necessary. Hopefully this overcomes the inactivity problem with the first link.

https://gitpod.io#snapshot/78f54083-c1b9-491e-8f23-88763b253643

Might be caused by a different version of pandas handling your renaming of the columns differently.

Add

print(pd.__version__)

To both the gitpod and VSCode to find out what version it is. You may need to upgrade or downgrade the version on gitpod.

Otherwise… maybe you can try just explicitly naming the last column, or all columns, instead of renaming by name (if it has trouble finding total)

>>> df.columns = ['a', 'b']
>>> df
   a   b
0  1  10
1  2  20

The versions are different between GitPod (1.5.3) and VScode (2.2.0). The requirements in the .txt file on GitPod are that Pandas be version 1.5.3 and seaborn be version 0.9.0. Given that, I opted to manually rename the columns and that did solve the initial problem and seaborn can now find the “total” column.

However, I am now given a new error regarding the “y” value that states numpy has no attribute ‘float’ (see image). I am not sure why since all of my values are int64 (except the variable names which are objects).

I attempted to manual set the type for ‘total’ to float and np.float64 and neither of those worked. I also attempted to upgrade numpy to the latest version, but when I did the terminal returns that the requirement is already satisfied.

I also tried to amend the requirements .txt to change seaborn and pandas version matching my VScode environment, and to upgrade python to 3.9. I was unable to get that to work.

Since the initial question was already answered, if it is best for me to mark that comment as the solution and to open up this question as a separate post please let me know. Thank you.

Read through the error message completely, the last sentences.

It sounds to me like the automated tests are using np.float but this was deprecated in numpy version 1.20. You may need to install an older version, instead of upgrading it.

Mine seems to work with 1.20.3. You can install it with this terminal command:

pip install --force-reinstall numpy==1.20.3

That allowed it to run. I am still receiving many errors that seem to be coming from the automated tests, but it does appear to at least complete all of the tests and output which ones were failed.

I think I can take it from here and troubleshoot on my own. If necessary, I can go through and rewrite parts of my code to be compatible with the versions being used. I appreciate the help!

1 Like

You got this!

Here are some versions that mine works with:
Python 3.8.18
numpy 1.20.3
Pandas 1.5.3

You can check like this:

import sys
print("Python",sys.version)
print("numpy", np.version.version)
print("Pandas", pd.__version__)

Just remember that some errors might come from your code, but some errors might come from the tests. It could get a bit hairy but a careful reading of the errors will have a lot of information.

Lastly, you can still get some warnings or other messages about deprecation but still pass the tests. If it ends like this:

Ran 4 tests in 1.712s

OK

You are basically good.

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