Welcome to the co u rse ! IN TR OD U C TION TO IMP OR TIN G DATA IN P YTH ON H u go Bo w ne - Anderson Data Scientist at DataCamp
Import data Flat � les , e . g . . t x ts , . cs v s Files from other so �w are INTRODUCTION TO IMPORTING DATA IN PYTHON
Import data Flat � les , e . g . . t x ts , . cs v s Files from other so �w are Relational databases INTRODUCTION TO IMPORTING DATA IN PYTHON
Plain te x t files INTRODUCTION TO IMPORTING DATA IN PYTHON
Table data 1 So u rce : Kaggle INTRODUCTION TO IMPORTING DATA IN PYTHON
Table data INTRODUCTION TO IMPORTING DATA IN PYTHON
Table data Flat � le INTRODUCTION TO IMPORTING DATA IN PYTHON
Reading a te x t file filename = 'huck_finn.txt' file = open(filename, mode='r') # 'r' is to read text = file.read() file.close() INTRODUCTION TO IMPORTING DATA IN PYTHON
Printing a te x t file print(text) YOU don't know about me without you have read a book by the name of The Adventures of Tom Sawyer; but that ain't no matter. That book was made by Mr. Mark Twain, and he told the truth, mainly. There was things which he stretched, but mainly he told the truth. That is nothing. never seen anybody but lied one time or another, without it was Aunt Polly, or the widow, or maybe Mary. Aunt Polly--Tom's Aunt Polly, she is--and Mary, and the Widow Douglas is all told about in that book, which is mostly a true book, with some stretchers, as I said before. INTRODUCTION TO IMPORTING DATA IN PYTHON
Writing to a file filename = 'huck_finn.txt' file = open(filename, mode='w') # 'w' is to write file.close() INTRODUCTION TO IMPORTING DATA IN PYTHON
Conte x t manager w ith with open('huck_finn.txt', 'r') as file: print(file.read()) YOU don't know about me without you have read a book by the name of The Adventures of Tom Sawyer; but that ain't no matter. That book was made by Mr. Mark Twain, and he told the truth, mainly. There was things which he stretched, but mainly he told the truth. That is nothing. never seen anybody but lied one time or another, without it was Aunt Polly, or the widow, or maybe Mary. Aunt Polly--Tom's Aunt Polly, she is--and Mary, and the Widow Douglas is all told about in that book, which is mostly a true book, with some stretchers, as I said before. INTRODUCTION TO IMPORTING DATA IN PYTHON
In the e x ercises , y o u’ ll : Print � les to the console Print speci � c lines Disc u ss � at � les INTRODUCTION TO IMPORTING DATA IN PYTHON
Let ' s practice ! IN TR OD U C TION TO IMP OR TIN G DATA IN P YTH ON
The importance of flat files in data science IN TR OD U C TION TO IMP OR TIN G DATA IN P YTH ON H u go Bo w ne - Anderson Data Scientist at DataCamp
Flat files INTRODUCTION TO IMPORTING DATA IN PYTHON
Flat files INTRODUCTION TO IMPORTING DATA IN PYTHON
Flat files INTRODUCTION TO IMPORTING DATA IN PYTHON
Flat files INTRODUCTION TO IMPORTING DATA IN PYTHON
Flat files Te x t � les containing records That is , table data Record : ro w of � elds or a � rib u tes INTRODUCTION TO IMPORTING DATA IN PYTHON
Flat files Te x t � les containing records That is , table data Record : ro w of � elds or a � rib u tes Col u mn : feat u re or a � rib u te INTRODUCTION TO IMPORTING DATA IN PYTHON
Flat files Te x t � les containing records That is , table data Record : ro w of � elds or a � rib u tes Col u mn : feat u re or a � rib u te INTRODUCTION TO IMPORTING DATA IN PYTHON
Header INTRODUCTION TO IMPORTING DATA IN PYTHON
Header INTRODUCTION TO IMPORTING DATA IN PYTHON
File e x tension . cs v - Comma separated v al u es . t x t - Te x t � le commas , tabs - Delimiters INTRODUCTION TO IMPORTING DATA IN PYTHON
Tab - delimited file INTRODUCTION TO IMPORTING DATA IN PYTHON
Tab - delimited file INTRODUCTION TO IMPORTING DATA IN PYTHON
Ho w do y o u import flat files ? T w o main packages : N u mP y, pandas Here , y o u’ ll learn to import : Flat � les w ith n u merical data ( MNIST ) Flat � les w ith n u merical data and strings ( titanic . cs v) INTRODUCTION TO IMPORTING DATA IN PYTHON
Let ' s practice ! IN TR OD U C TION TO IMP OR TIN G DATA IN P YTH ON
Importing flat files u sing N u mP y IN TR OD U C TION TO IMP OR TIN G DATA IN P YTH ON H u go Bo w ne - Anderson Data Scientist at DataCamp
Wh y N u mP y? N u mP y arra y s : standard for storing n u merical data INTRODUCTION TO IMPORTING DATA IN PYTHON
Wh y N u mP y? N u mP y arra y s : standard for storing n u merical data Essential for other packages : e . g . scikit - learn loadt x t () genfromt x t () INTRODUCTION TO IMPORTING DATA IN PYTHON
Importing flat files u sing N u mP y import numpy as np filename = 'MNIST.txt' data = np.loadtxt(filename, delimiter=',') data [[ 0. 0. 0. 0. 0.] [ 86. 250. 254. 254. 254.] [ 0. 0. 0. 9. 254.] ..., [ 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0.]] INTRODUCTION TO IMPORTING DATA IN PYTHON
C u stomi z ing y o u r N u mP y import import numpy as np filename = 'MNIST_header.txt' data = np.loadtxt(filename, delimiter=',', skiprows=1) print(data) [[ 0. 0. 0. 0. 0.] [ 86. 250. 254. 254. 254.] [ 0. 0. 0. 9. 254.] ..., [ 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0.]] INTRODUCTION TO IMPORTING DATA IN PYTHON
C u stomi z ing y o u r N u mP y import import numpy as np filename = 'MNIST_header.txt' data = np.loadtxt(filename, delimiter=',', skiprows=1, usecols=[0, 2]) print(data) [[ 0. 0.] [ 86. 254.] [ 0. 0.] ..., [ 0. 0.] [ 0. 0.] [ 0. 0.]] INTRODUCTION TO IMPORTING DATA IN PYTHON
C u stomi z ing y o u r N u mP y import data = np.loadtxt(filename, delimiter=',', dtype=str) INTRODUCTION TO IMPORTING DATA IN PYTHON
Mi x ed datat y pes 1 So u rce : Kaggle INTRODUCTION TO IMPORTING DATA IN PYTHON
Mi x ed datat y pes INTRODUCTION TO IMPORTING DATA IN PYTHON
Let ' s practice ! IN TR OD U C TION TO IMP OR TIN G DATA IN P YTH ON
Importing flat files u sing pandas IN TR OD U C TION TO IMP OR TIN G DATA IN P YTH ON H u go Bo w ne - Anderson Data Scientist at DataCamp
What a data scientist needs T w o - dimensional labeled data str u ct u re ( s ) Col u mns of potentiall y di � erent t y pes Manip u late , slice , reshape , gro u pb y, join , merge Perform statistics Work w ith time series data INTRODUCTION TO IMPORTING DATA IN PYTHON
Pandas and the DataFrame INTRODUCTION TO IMPORTING DATA IN PYTHON
Pandas and the DataFrame INTRODUCTION TO IMPORTING DATA IN PYTHON
Pandas and the DataFrame DataFrame = p y thonic analog of R ’ s data frame INTRODUCTION TO IMPORTING DATA IN PYTHON
Pandas and the DataFrame INTRODUCTION TO IMPORTING DATA IN PYTHON
Manip u lating pandas DataFrames E x plorator y data anal y sis Data w rangling Data preprocessing B u ilding models Vis u ali z ation Standard and best practice to u se pandas INTRODUCTION TO IMPORTING DATA IN PYTHON
Importing u sing pandas import pandas as pd filename = 'winequality-red.csv' data = pd.read_csv(filename) data.head() volatile acidity citric acid residual sugar 0 0.70 0.00 1.9 1 0.88 0.00 2.6 2 0.76 0.04 2.3 3 0.28 0.56 1.9 4 0.70 0.00 1.9 data_array = data.values INTRODUCTION TO IMPORTING DATA IN PYTHON
Yo u’ ll e x perience : Importing � at � les in a straightfor w ard manner Importing � at � les w ith iss u es s u ch as comments and missing v al u es INTRODUCTION TO IMPORTING DATA IN PYTHON
Let ' s practice ! IN TR OD U C TION TO IMP OR TIN G DATA IN P YTH ON
Final tho u ghts on data import IN TR OD U C TION TO IMP OR TIN G DATA IN P YTH ON H u go Bo w ne - Anderson Data Scientist at DataCamp
Ne x t chapters : Import other � le t y pes : E x cel , SAS , Stata Feather Interact w ith relational databases INTRODUCTION TO IMPORTING DATA IN PYTHON
Ne x t co u rse : Scrape data from the w eb Interact w ith APIs INTRODUCTION TO IMPORTING DATA IN PYTHON
Let ' s practice ! IN TR OD U C TION TO IMP OR TIN G DATA IN P YTH ON
Recommend
More recommend