Import From.csv
- 01:32
How to create dataframes from both Excel and CSV files using Pandas in Python.
Downloads
No associated resources to download.
Transcript
Similarly, if you're importing from a csv file, you can replace that read Excel function with the read csv function, execute that cell to create your csv dataframe, and then it will show up exactly the same.
Pandas doesn't care if it's getting the data from Excel or a csv file or one of several other data sources.
If you're using the right function, then it'll be able to create your dataframe for you automatically.
Just be careful as you're doing that, that you're using the right extension for the file where you're getting your data.
If you get the same results in your dataframe, why would you use a csv file instead of an Excel file? Well, right now it doesn't matter that much because we're using such small amounts of data, but there's actually a huge difference in the size of these files.
Here you can see the csv file, and it's only 93 bytes.
If I look at the exact same data in Excel, it's 8.21 kilobytes.
That's almost 90 times larger than the csv file for the same exact data.
Now, this table only has three observations, so both files are small enough that we don't care.
But what if you were performing a machine learning analysis with 3000 observations or 3 million observations before too long, that 90 times difference in file size starts to matter.
So it's good to know how to create a dataframe using both methods.