Pandas Readcsv Tutorial
Key Takeaways
This video tutorial covers the basics of reading CSV files using Python's Pandas library, including default options, custom delimiters, and handling missing values.
Full Transcript
CSP or comma separated values files are very common for data analysis you'll often want to import them fortunately the pandas package makes it straightforward to import data in this format the tricky part is that there's no standard format for CSV files which means you'll need to play around with a lot of the options we'll cover the most common ones here throughout this video we'll repeatedly import a data set about the most popular media franchises first we import the pandas package with the conventional alias PD let's read a CSV file that's standard enough that we can use default options I'll use the file browser to open it notice that the Top Line contains the names of the columns this is called the header row other lines contain one observation in this case a media franchise notice that each value is separated by a comma hence the name comma separated values also notice that string columns are quoted this is common but doesn't always Happ back to the code to read a CSV file call PD then a DOT then read uncore csb it's a function so we need parentheses to use the default arguments we just need the file name default. CSV one variation in CSV files is that there is no header row included this is common when the data was exported from a database let's see the file in the file browser the contents are the same as before but the first line is missing back to the code we need to specify the column names ourselves as a list of strings stored here in the column undor names variable again we call pd. read CSV and pass the file path this time we also need the names argument sometimes time CSV files use the tab character instead of commas to separate the values the separator character is sometimes called the delimiter separating and delimiting mean the same thing in the file browser you can see gaps between the values these are the tabs also notice that the strings haven't been quoted this is common when you have tab delimited files in the code as per usual we call pd. read CSV and pass the file path to specify tabs of separators we use the SE argument and set it to backt in quotes a similar variation to tab separators is European formatted CSV files in countries where a comma is used as a decimal place it's confusing to use a comma to separate values as well looking at the file you can see commas used as decimal places and semicolons are used to delimit the cells once again we call pd. read CSV and pass the file path as with the tab to limited case we call Se this time giving it a semicolon we also need to use the decimal argument passing a comma the data on a CSV file doesn't always start on the first row in this variant of the file the first few rows are taken up with a data dictionary written in yaml format documenting your data is a great idea to assist the analyst but we need to ignore it when reading in the data by now you know the routine call pd. read CSV and pass the file path the data starts on row nine so we skip the first eight rows by setting skip rows to eight one more variation in CSV files is how missing values are dealt with in the franchises data set some franchises are missing the value for the number of movies pandis has fairly sophisticated missing value detection but if a non-standard value is used you need to deal with it in this variation missing values are denoted with the question Mark we call pd. read CSV and pass the file path then pass naor values set to a question mark it's common to not need to use every column in a data set for large data sets it's much faster to ignore the columns you don't need during import rather than reading everything than taking a subset as always we call pd. read CSV and pass the file path you can specify the coms you want to keep with use calls set to the list variable calls to keep pandis usually does a good job of determining what the data types for each column should be sometimes you'll want to override the default Choice inspecting the data types for each column you'll notice that Inception year is imported as an integer that might be useful but you might prefer that it is read as a datetime object we call pd. read CSP and pass the file path then use past dates to request that columns are converted to datetime objects this takes a list of column names here we just want Inception year inside the list thank you for watching I'm Richie and if you enjoyed the video please subscribe to the channel to stay up toate with the latest data and AI content
Original Description
This Python Pandas tutorial for beginners will take you through some of the basics of reading CSV files. The topics covered in this video are:
00:00 - 00:27 Introduction
00:28 - 01:22 Read CSV with Default Options
01:23 - 02:01 Read CSV with no Header Row
02:02 - 02:42 Using Tabs as Delimiters
02:43 - 03:13 European Formatting
03:14 - 03:41 Reading a CSV File that Doesn't Start at the Beginning
03:42 - 04:09 Nonstandard Missing Values
04:10 - 04:34 Reading a Subset of a CSV File
04:35 - 05:08 Controlling the Data Types of Columns
05:09 - 05:27 Outro
[Try it yourself!]
Pre-prepared DataLab Workbook: https://bit.ly/3V4ifWI
[More about Python]
Python is the most popular programming language today and is widely used across verticals from software and web development, game development, data science, machine learning, and more. Learning Python is imperative for aspiring data scientists, data analysts, data engineers, and machine learning scientists.
Subscribe to our YouTube Channel
Read our cheat sheets! - https://www.datacamp.com/cheat-sheet
Instagram: / datacamp
Twitter: / datacamp
Facebook: / datacampinc
YouTube: / @datacamp
LinkedIn: / datacampinc
Website: https://www.datacamp.com/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: ML Pipelines
View skill →Related Reads
📰
📰
📰
📰
I Don’t Want to Build Another App. I Want to Find Out Where the Models Break.
Medium · Machine Learning
A Graph Neural Network Model for Real-Time Gesture Recognition Based on sEMG Signals
ArXiv cs.AI
Evaluating the Effect of Frame Rate in Sequence-Based Classification of Autism-Related Self-Stimulatory Hand Idiosyncrasies
ArXiv cs.AI
Measure, Don't Estimate: Labeling Speakers Without a Gated Model
Dev.to · Dima Statz
Chapters (10)
00:27 Introduction
0:28
01:22 Read CSV with Default Options
1:23
02:01 Read CSV with no Header Row
2:02
02:42 Using Tabs as Delimiters
2:43
03:13 European Formatting
3:14
03:41 Reading a CSV File that Doesn't Start at the Beginning
3:42
04:09 Nonstandard Missing Values
4:10
04:34 Reading a Subset of a CSV File
4:35
05:08 Controlling the Data Types of Columns
5:09
05:27 Outro
🎓
Tutor Explanation
DeepCamp AI