.read_csv()
StevenSwiniarski474 total contributions
Published May 12, 2022
Contribute to Docs
The .read_csv()
function takes a path to a CSV file and reads the data into a Pandas DataFrame
object.
Syntax
pandas.read_csv(filepath_or_buffer)
The filepath_or_buffer
parameter is the path to the CSV file. It can be a path on the local machine or a valid URL. It is the first parameter of the function and can be used by itself. There are, however, many other parameters that are optional or have default settings. These are usually passed as keyword arguments since using the parameter order is generally inconvenient.
Some of the more significant parameters are listed here:
Parameter Name | Data Type | Usage |
---|---|---|
filepath_or_buffer |
str | Path to the CSV file to import. |
sep |
str | Delimiter to use. Values longer than 1 character will be interpreted as Regular Expressions. |
delimiter |
str | alias for sep . |
header |
int, list of int, None | Row number(s) to use as column names, and start of data. |
names |
array-like | List of column names to use. If file contains a header row, explicitly set header=0 to override the column names. |
usecols |
list-like or callable | List of column numbers or names to import. If callable, uses columns where the name passed to the callable results in True . |
skiprows |
list-like, int or callable | Initial lines to skip (int). Row numbers to skip (list). Or callable that returns True when the row number passed to it should be skipped. |
skip_blank_lines |
bool | True to skip blank lines rather than reading NaN values. Default is True . |
Example
import pandasdf = pandas.read_csv("data.csv")print(df)
Output will show the contents of the CSV file loaded into the DataFrame:
column 1 column 2 column 30 A B C1 D E F
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.