Reading CSV and Excel Files
Load data from CSV, Excel, and multiple sheets into Pandas DataFrames
Reading data is the first step of every analysis. Pandas has powerful read functions that handle most real-world file formats with a single line. Knowing the right parameters prevents common issues like wrong data types on load, encoding errors, and extra header/footer rows that come from exported reports.
Examples
Key Points
- ✓pd.read_csv() and pd.read_excel() are your primary data loading functions
- ✓Always check df.dtypes after loading — wrong types are the #1 source of calculation errors
- ✓encoding="latin-1" fixes UnicodeDecodeError on files exported from older Indian systems
- ✓parse_dates=["Date"] saves you from manually converting date columns after loading
- ✓dtype={"col": str} forces a column to stay as text — critical for ID and code columns
Practice Question
Your CSV file has a "PinCode" column that Pandas reads as integer (011041 becomes 11041). How do you fix this on load?
Related Topics
Pandas DataFramesThe core Pandas data structure — a 2D table with rows and columnsData Cleaning with PandasRename columns, fix data types, remove duplicates, and standardise messy real-world dataFile Handling in PythonRead and write text files, CSV files, and automate file operations for data pipelines