Data Analysis with Python Projects - Medical Data Visualizer

Tell us what’s happening: I am getting below error

Traceback (most recent call last):
File “/home/runner/boilerplate-medical-data-visualizer/main.py”, line 2, in
import medical_data_visualizer
File “/home/runner/boilerplate-medical-data-visualizer/medical_data_visualizer.py”, line 1, in
import pandas as pd
ModuleNotFoundError: No module named ‘pandas’

Your code so far

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

df[‘overweight’] = np.where((df[‘weight’]/(df[‘height’]/100)**2) > 25, 1, 0)

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.

df[“cholesterol”] = np.where(df[“cholesterol”] == 1, 0, 1)
df[“gluc”] = np.where(df[“gluc”] == 1, 0, 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 = pd.melt(df, id_vars=[‘cardio’], value_vars=[‘cholesterol’, ‘gluc’, ‘smoke’, ‘alco’, ‘active’, ‘overweight’])

# 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_cat["total"] = 1
df_cat = df_cat.groupby(["cardio", "variable", "value"], as_index= False).count()


# Draw the catplot with 'sns.catplot()'

# Get the figure for the output
fig = sns.catplot(x="variable", y="total", hue="value", data=df_cat, kind="bar", col="cardio").fig


# Do not modify the next two lines
fig.savefig('catplot.png')
return fig

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36

Challenge Information:

Data Analysis with Python Projects - Medical Data Visualizer

ModuleNotFoundError: No module named ‘pandas’

pip install pandas

which version i need to install?

Don’t worry about that yet, pip should install the latest or check a dependencies list and install something appropriate.

Now got below errors:

Packager:

→ poetry add matplotlib numpy
Using version ^3.8.2 for matplotlib
Using version ^1.26.2 for numpy

Updating dependencies
Resolving dependencies…

The current project’s Python requirement (>=3.7,<4.0) is not compatible with some of the required packages Python requirement:

  • numpy requires Python >=3.9, so it will not be satisfied for Python >=3.7,<3.9

Because no versions of numpy match >1.26.2,<2.0.0
and numpy (1.26.2) requires Python >=3.9, numpy is forbidden.
So, because root depends on numpy (^1.26.2), version solving failed.

• Check your dependencies Python requirement: The Python requirement can be specified via the python or markers properties

For numpy, a possible solution would be to set the `python` property to ">=3.9,<4.0"

https://python-poetry.org/docs/dependency-specification/#python-restricted-dependencies,
https://python-poetry.org/docs/dependency-specification/#using-environment-markers

exit status 1

Run:
Requirement already satisfied: pandas in ./.pythonlibs/lib/python3.10/site-packages (2.1.3)
Requirement already satisfied: tzdata>=2022.1 in ./.pythonlibs/lib/python3.10/site-packages (from pandas) (2023.3)
Requirement already satisfied: python-dateutil>=2.8.2 in ./.pythonlibs/lib/python3.10/site-packages (from pandas) (2.8.2)
Requirement already satisfied: numpy<2,>=1.22.4 in ./.pythonlibs/lib/python3.10/site-packages (from pandas) (1.26.2)
Requirement already satisfied: pytz>=2020.1 in ./.pythonlibs/lib/python3.10/site-packages (from pandas) (2023.3.post1)
Requirement already satisfied: six>=1.5 in ./.pythonlibs/lib/python3.10/site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)

Link to your replit please

Try this: https://forum.freecodecamp.org/t/data-analysis-with-python-projects-page-view-time-series-visualizer/650118/2?u=pkdvalis

In the Files menu to the side, show hidden files and then delete poetry.lock, pyproject.toml and replit.nix

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