In [12]:
import pandas as pd

df = pd.read_csv("E:\Development\Medical_Agent\data\HAM10000\HAM10000_metadata.csv")

print(df.head())
     lesion_id      image_id   dx dx_type   age   sex localization  \
0  HAM_0000118  ISIC_0027419  bkl   histo  80.0  male        scalp   
1  HAM_0000118  ISIC_0025030  bkl   histo  80.0  male        scalp   
2  HAM_0002730  ISIC_0026769  bkl   histo  80.0  male        scalp   
3  HAM_0002730  ISIC_0025661  bkl   histo  80.0  male        scalp   
4  HAM_0001466  ISIC_0031633  bkl   histo  75.0  male          ear   

        dataset  
0  vidir_modern  
1  vidir_modern  
2  vidir_modern  
3  vidir_modern  
4  vidir_modern  
In [14]:
print(df.info())
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10015 entries, 0 to 10014
Data columns (total 8 columns):
 #   Column        Non-Null Count  Dtype  
---  ------        --------------  -----  
 0   lesion_id     10015 non-null  object 
 1   image_id      10015 non-null  object 
 2   dx            10015 non-null  object 
 3   dx_type       10015 non-null  object 
 4   age           9958 non-null   float64
 5   sex           10015 non-null  object 
 6   localization  10015 non-null  object 
 7   dataset       10015 non-null  object 
dtypes: float64(1), object(7)
memory usage: 626.1+ KB
None
In [15]:
print(df.describe())
               age
count  9958.000000
mean     51.863828
std      16.968614
min       0.000000
25%      40.000000
50%      50.000000
75%      65.000000
max      85.000000
In [16]:
print(df.isnull().sum())
lesion_id        0
image_id         0
dx               0
dx_type          0
age             57
sex              0
localization     0
dataset          0
dtype: int64
In [13]:
import matplotlib.pyplot as plt

df["dx"].value_counts().plot(kind="bar")

plt.title("Disease Distribution")

plt.xlabel("Disease")

plt.ylabel("Number of Images")

plt.show()
No description has been provided for this image
In [7]:
df["age"].hist(bins=20)

plt.xlabel("Age")

plt.ylabel("Count")

plt.title("Age Distribution")

plt.show()
No description has been provided for this image
In [17]:
df["sex"].value_counts().plot(kind="pie", autopct="%1.1f%%")
plt.ylabel("")
plt.show()
No description has been provided for this image
In [18]:
df["localization"].value_counts()
Out[18]:
localization
back               2192
lower extremity    2077
trunk              1404
upper extremity    1118
abdomen            1022
face                745
chest               407
foot                319
unknown             234
neck                168
scalp               128
hand                 90
ear                  56
genital              48
acral                 7
Name: count, dtype: int64
In [19]:
df["localization"].value_counts().plot(kind="bar")

plt.xticks(rotation=45)

plt.show()
No description has been provided for this image
In [20]:
pd.crosstab(df["dx"], df["localization"])
Out[20]:
localization abdomen acral back chest ear face foot genital hand lower extremity neck scalp trunk unknown upper extremity
dx
akiec 5 0 29 12 3 113 0 0 13 65 10 14 1 0 62
bcc 18 0 186 47 0 101 4 0 2 58 14 19 11 5 49
bkl 42 0 202 74 6 319 1 2 14 174 31 34 73 23 104
df 4 0 2 0 0 0 2 1 0 82 0 0 0 0 24
mel 66 0 324 68 17 104 28 0 1 192 29 14 47 10 213
nv 860 7 1427 200 30 100 284 45 55 1479 81 45 1241 196 655
vasc 27 0 22 6 0 8 0 0 5 27 3 2 31 0 11
In [21]:
df.groupby("dx")["age"].mean()
Out[21]:
dx
akiec    66.529052
bcc      66.828794
bkl      64.283747
df       53.043478
mel      60.679568
nv       46.477477
vasc     51.373239
Name: age, dtype: float64
In [22]:
pd.crosstab(df["dx"], df["sex"])
Out[22]:
sex female male unknown
dx
akiec 106 221 0
bcc 197 317 0
bkl 463 626 10
df 52 63 0
mel 424 689 0
nv 3237 3421 47
vasc 73 69 0