Python para enfermeiras (22)¶
Análise Exploratória de Dados: um exercício¶
In [1]:
# Importando os pacotes
import numpy as np
import pandas as pd
import matplotlib as mat
import matplotlib.pyplot as plt
import colorsys # criar gráficos
plt.style.use('seaborn-talk')
import warnings
warnings.filterwarnings("ignore")
%matplotlib inline
In [2]:
# Carregando o dataset
df = pd.read_csv("Dados-Pesquisa.csv", sep = ',', low_memory=False)
In [3]:
# mostrar as 5 primeiras linhas do conjunto de dados
print(df.head())
Age AttendedBootcamp BootcampFinish BootcampFullJobAfter \
0 28.0 0.0 NaN NaN
1 22.0 0.0 NaN NaN
2 19.0 0.0 NaN NaN
3 26.0 0.0 NaN NaN
4 20.0 0.0 NaN NaN
BootcampLoanYesNo BootcampMonthsAgo BootcampName BootcampPostSalary \
0 NaN NaN NaN NaN
1 NaN NaN NaN NaN
2 NaN NaN NaN NaN
3 NaN NaN NaN NaN
4 NaN NaN NaN NaN
BootcampRecommend ChildrenNumber ... ResourceSoloLearn \
0 NaN NaN ... NaN
1 NaN NaN ... NaN
2 NaN NaN ... NaN
3 NaN NaN ... NaN
4 NaN NaN ... NaN
ResourceStackOverflow ResourceTreehouse ResourceUdacity ResourceUdemy \
0 NaN NaN NaN NaN
1 NaN NaN NaN 1.0
2 NaN NaN NaN NaN
3 NaN NaN NaN NaN
4 NaN NaN NaN NaN
ResourceW3Schools ResourceYouTube \
0 NaN NaN
1 NaN NaN
2 NaN NaN
3 NaN NaN
4 NaN NaN
SchoolDegree SchoolMajor \
0 some college credit, no degree NaN
1 some college credit, no degree NaN
2 high school diploma or equivalent (GED) NaN
3 bachelor's degree Cinematography And Film
4 some college credit, no degree NaN
StudentDebtOwe
0 20000.0
1 NaN
2 NaN
3 7000.0
4 NaN
[5 rows x 113 columns]
In [4]:
# como este conjunto de dados tem muitas colunas, foi fatiado (\) na exibição.
# mostrar o dataframe(df) para ficar mais compreensível
df
Out[4]:
| Age | AttendedBootcamp | BootcampFinish | BootcampFullJobAfter | BootcampLoanYesNo | BootcampMonthsAgo | BootcampName | BootcampPostSalary | BootcampRecommend | ChildrenNumber | ... | ResourceSoloLearn | ResourceStackOverflow | ResourceTreehouse | ResourceUdacity | ResourceUdemy | ResourceW3Schools | ResourceYouTube | SchoolDegree | SchoolMajor | StudentDebtOwe | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 28.0 | 0.0 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | some college credit, no degree | NaN | 20000.0 |
| 1 | 22.0 | 0.0 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | 1.0 | NaN | NaN | some college credit, no degree | NaN | NaN |
| 2 | 19.0 | 0.0 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | high school diploma or equivalent (GED) | NaN | NaN |
| 3 | 26.0 | 0.0 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | bachelor's degree | Cinematography And Film | 7000.0 |
| 4 | 20.0 | 0.0 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | some college credit, no degree | NaN | NaN |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 15615 | 39.0 | 0.0 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | 1.0 | NaN | NaN | bachelor's degree | Chemistry | NaN |
| 15616 | 27.0 | 0.0 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | 1.0 | NaN | NaN | NaN | NaN | bachelor's degree | Electrical Engineering | NaN |
| 15617 | 37.0 | 0.0 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | bachelor's degree | Chemistry | NaN |
| 15618 | 26.0 | 0.0 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | 1.0 | NaN | NaN | master's degree (non-professional) | Math | NaN |
| 15619 | 22.0 | 0.0 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | bachelor's degree | Graphic Design | 40000.0 |
15620 rows × 113 columns
In [5]:
'''Este singelo questionário de pesquisa gerou um conjunto de dados com 113 colunas e 15620 linhas!!!
Ao visualizar o conjunto de dados, é possível notar muitos NaN, ou seja, valores missing (faltando).
Vamos explorar a totalidade do conjunto de dados (DF) usando a função describe.
O Pandas (pd) gerará, de forma simples e rápida, um conjunto de estatísticas descritivas deste dataset (df)'''
print(df.describe())
Age AttendedBootcamp BootcampFinish BootcampFullJobAfter \
count 13613.000000 15380.000000 933.000000 635.000000
mean 29.175714 0.061964 0.689175 0.584252
std 9.017580 0.241097 0.463080 0.493239
min 10.000000 0.000000 0.000000 0.000000
25% 23.000000 0.000000 0.000000 0.000000
50% 27.000000 0.000000 1.000000 1.000000
75% 33.000000 0.000000 1.000000 1.000000
max 86.000000 1.000000 1.000000 1.000000
BootcampLoanYesNo BootcampMonthsAgo BootcampPostSalary \
count 934.000000 631.000000 330.000000
mean 0.332976 9.055468 63740.506061
std 0.471531 12.968035 26347.200265
min 0.000000 0.000000 6000.000000
25% 0.000000 3.000000 50000.000000
50% 0.000000 6.000000 60000.000000
75% 1.000000 12.000000 77000.000000
max 1.000000 220.000000 200000.000000
BootcampRecommend ChildrenNumber CodeEventBootcamp ... \
count 937.000000 2554.000000 42.0 ...
mean 0.785486 1.896241 1.0 ...
std 0.410704 1.115975 0.0 ...
min 0.000000 0.000000 1.0 ...
25% 1.000000 1.000000 1.0 ...
50% 1.000000 2.000000 1.0 ...
75% 1.000000 2.000000 1.0 ...
max 1.000000 18.000000 1.0 ...
ResourceReddit ResourceSkillCrush ResourceSoloLearn \
count 29.0 36.0 30.0
mean 1.0 1.0 1.0
std 0.0 0.0 0.0
min 1.0 1.0 1.0
25% 1.0 1.0 1.0
50% 1.0 1.0 1.0
75% 1.0 1.0 1.0
max 1.0 1.0 1.0
ResourceStackOverflow ResourceTreehouse ResourceUdacity \
count 191.0 422.0 3306.0
mean 1.0 1.0 1.0
std 0.0 0.0 0.0
min 1.0 1.0 1.0
25% 1.0 1.0 1.0
50% 1.0 1.0 1.0
75% 1.0 1.0 1.0
max 1.0 1.0 1.0
ResourceUdemy ResourceW3Schools ResourceYouTube StudentDebtOwe
count 4130.0 121.0 121.0 3514.000000
mean 1.0 1.0 1.0 34556.143711
std 0.0 0.0 0.0 54423.139781
min 1.0 1.0 1.0 0.000000
25% 1.0 1.0 1.0 10000.000000
50% 1.0 1.0 1.0 20000.000000
75% 1.0 1.0 1.0 40000.000000
max 1.0 1.0 1.0 1000000.000000
[8 rows x 85 columns]
In [6]:
# Lista todas as 85 colunas do conjunto de dados
list(df)
Out[6]:
['Age', 'AttendedBootcamp', 'BootcampFinish', 'BootcampFullJobAfter', 'BootcampLoanYesNo', 'BootcampMonthsAgo', 'BootcampName', 'BootcampPostSalary', 'BootcampRecommend', 'ChildrenNumber', 'CityPopulation', 'CodeEventBootcamp', 'CodeEventCoffee', 'CodeEventConferences', 'CodeEventDjangoGirls', 'CodeEventGameJam', 'CodeEventGirlDev', 'CodeEventHackathons', 'CodeEventMeetup', 'CodeEventNodeSchool', 'CodeEventNone', 'CodeEventOther', 'CodeEventRailsBridge', 'CodeEventRailsGirls', 'CodeEventStartUpWknd', 'CodeEventWomenCode', 'CodeEventWorkshop', 'CommuteTime', 'CountryCitizen', 'CountryLive', 'EmploymentField', 'EmploymentFieldOther', 'EmploymentStatus', 'EmploymentStatusOther', 'ExpectedEarning', 'FinanciallySupporting', 'Gender', 'HasChildren', 'HasDebt', 'HasFinancialDependents', 'HasHighSpdInternet', 'HasHomeMortgage', 'HasServedInMilitary', 'HasStudentDebt', 'HomeMortgageOwe', 'HoursLearning', 'ID.x', 'ID.y', 'Income', 'IsEthnicMinority', 'IsReceiveDiabilitiesBenefits', 'IsSoftwareDev', 'IsUnderEmployed', 'JobApplyWhen', 'JobPref', 'JobRelocateYesNo', 'JobRoleInterest', 'JobRoleInterestOther', 'JobWherePref', 'LanguageAtHome', 'MaritalStatus', 'MoneyForLearning', 'MonthsProgramming', 'NetworkID', 'Part1EndTime', 'Part1StartTime', 'Part2EndTime', 'Part2StartTime', 'PodcastChangeLog', 'PodcastCodeNewbie', 'PodcastCodingBlocks', 'PodcastDeveloperTea', 'PodcastDotNetRocks', 'PodcastHanselminutes', 'PodcastJSJabber', 'PodcastJsAir', 'PodcastNone', 'PodcastOther', 'PodcastProgrammingThrowDown', 'PodcastRubyRogues', 'PodcastSEDaily', 'PodcastShopTalk', 'PodcastTalkPython', 'PodcastWebAhead', 'ResourceBlogs', 'ResourceBooks', 'ResourceCodeWars', 'ResourceCodecademy', 'ResourceCoursera', 'ResourceDevTips', 'ResourceEdX', 'ResourceEggHead', 'ResourceFCC', 'ResourceGoogle', 'ResourceHackerRank', 'ResourceKhanAcademy', 'ResourceLynda', 'ResourceMDN', 'ResourceOdinProj', 'ResourceOther', 'ResourcePluralSight', 'ResourceReddit', 'ResourceSkillCrush', 'ResourceSoloLearn', 'ResourceStackOverflow', 'ResourceTreehouse', 'ResourceUdacity', 'ResourceUdemy', 'ResourceW3Schools', 'ResourceYouTube', 'SchoolDegree', 'SchoolMajor', 'StudentDebtOwe']
Iniciando o tratamento dos dados...¶
idade das pessoas da amostra, por exemplo¶
In [7]:
# Qual a distribuição de idade das(os) participantes da pesquisa?
# A maioria das(os) profissionais que trabalha na área
# está na faixa de idade entre 20 e 30 anos, sendo 25 anos
# a idade mais frequente.
# Gerando um histograma
df.Age.hist(bins = 60) # bins são colunas
plt.xlabel("Idade")
plt.ylabel("Número de Profissionais")
plt.title("Distribuição de Idade")
plt.show()
distribuição do sexo, por exemplo¶
In [8]:
# Qual é a distribuição de sexo/gênero das(os) participantes da pesquisa?
# Definindo a quantidade
labels = df.Gender.value_counts().index
num = len(df.EmploymentField.value_counts().index)
# Criando a lista de cores
listaHSV = [(x*1.0/num, 0.5, 0.5) for x in range(num)]
listaRGB = list(map(lambda x: colorsys.hsv_to_rgb(*x), listaHSV))
# Gráfico de Pizza
fatias, texto = plt.pie(df.Gender.value_counts(), colors = listaRGB, startangle = 90)
plt.axes().set_aspect('equal', 'datalim')
plt.legend(fatias, labels, bbox_to_anchor = (1.05,1))
plt.title("Sexo/Gênero")
plt.show()
idade versus horas de aprendizagem, por exemplo¶
In [11]:
# Qual a relação entre idade e horas de aprendizagem (regressão linear simples)?
# criado um subconjunto de dados (df9)
import warnings
warnings.filterwarnings('ignore')
# Criando subset dos dados
df9 = df.copy()
df9 = df9.dropna(subset=["HoursLearning"])
df9 = df9[df['Age'].isin(range(10,80))]
# Definindo os valores de x e y
x = df9.Age
y = df9.HoursLearning
# Computando os valores e gerando o gráfico
m, b = np.polyfit(x, y, 1)
plt.plot(x, y, '.')
plt.plot(x, m*x + b, '-', color = "red")
plt.xlabel("Idade")
plt.ylabel("Horas de Treinamento")
plt.title("Idade por Horas de Treinamento")
plt.show()
Apontamentos
- Não há apontamentos.
BNN - ISSN 1676-4893
Boletim do Núcleo de Estudos e Pesquisas sobre as Atividades de Enfermagem (NEPAE)e do Núcleo de Estudos sobre Saúde e Etnia Negra (NESEN).
