Docsity

Streamline Data for Data Camp, Esquemas de Bancos de Dados Relacionais

Pré-visualização parcial do texto

Baixe Streamline Data for Data Camp e outras Esquemas em PDF para Bancos de Dados Relacionais, somente na Docsity!

Introduction to

spreadsheets

S T R E A M L I N E D D ATA I N G E S T I O N W I T H PA N D A S Amany Mahfouz Instructor

Spreadsheets

Also known as Excel les Data stored in tabular form, with cells arranged in rows and columns Unlike at les, can have formaing and formulas Multiple spreadsheets can exist in a workbook

Loading Spreadsheets

import pandas as pd

Read the Excel file

survey_data = pd.read_excel("fcc_survey.xlsx")

View the first 5 lines of data

print(survey_data.head()) Age AttendedBootcamp ... SchoolMajor StudentDebtOwe 0 28.0 0.0 ... NaN 20000 1 22.0 0.0 ... NaN NaN 2 19.0 0.0 ... NaN NaN 3 26.0 0.0 ... Cinematography And Film 7000 4 20.0 0.0 ... NaN NaN [5 rows x 98 columns]

Loading Select Columns and Rows

Loading Select Columns and Rows

Loading Select Columns and Rows

Read columns W-AB and AR of file, skipping metadata header

survey_data = pd.read_excel("fcc_survey_with_headers.xlsx", skiprows= 2 , usecols="W:AB, AR")

View data

print(survey_data.head()) CommuteTime CountryCitizen ... EmploymentFieldOther EmploymentStatus Income 0 35.0 United States of America ... NaN Employed for wages 32000. 1 90.0 United States of America ... NaN Employed for wages 15000. 2 45.0 United States of America ... NaN Employed for wages 48000. 3 45.0 United States of America ... NaN Employed for wages 43000. 4 10.0 United States of America ... NaN Employed for wages 6000. [5 rows x 7 columns]

Getting data from

multiple worksheets

S T R E A M L I N E D D ATA I N G E S T I O N W I T H PA N D A S Amany Mahfouz Instructor

Selecting Sheets to Load

read_excel() loads the rst sheet in an Excel le by default Use the sheet_name keyword argument to load other sheets Specify spreadsheets by name and/or (zero-indexed) position number Pass a list of names/numbers to load more than one sheet at a time Any arguments passed to read_excel() apply to all sheets read

Loading Select Sheets

Get the second sheet by position index

survey_data_sheet2 = pd.read_excel('fcc_survey.xlsx', sheet_name= 1 )

Get the second sheet by name

survey_data_2017 = pd.read_excel('fcc_survey.xlsx', sheet_name='2017') print(survey_data_sheet2.equals(survey_data_2017)) True

Loading All Sheets

Passing sheet_name=None to read_excel() reads all sheets in a workbook survey_responses = pd.read_excel("fcc_survey.xlsx", sheet_name=None) print(type(survey_responses))

for key, value in survey_responses.items(): print(key, type(value)) 2016 2017

Let's practice!

Modifying imports:

true/false data

S T R E A M L I N E D D ATA I N G E S T I O N W I T H PA N D A S Amany Mahfouz Instructor

Boolean Data

Boolean Data