pd.read_csv
时间: 2023-10-18 12:15:06 浏览: 81
pd.read_csv() is a function in the pandas library of Python that reads a CSV (Comma Separated Values) file and returns a pandas DataFrame. The function takes a file path as an argument and can also take several optional parameters like delimiter, header, encoding, etc.
Syntax:
```python
pd.read_csv(filepath_or_buffer, sep=',', delimiter=None, header='infer', names=None, index_col=None, usecols=None, dtype=None, skiprows=None, nrows=None, skip_blank_lines=True, na_values=None, keep_default_na=True, verbose=False, skipinitialspace=False, converters=None, encoding=None, squeeze=False)
```
Some of the commonly used parameters of pd.read_csv() are:
- filepath_or_buffer: the path to the CSV file or a URL.
- sep: the delimiter used in the CSV file.
- header: the row number(s) to use as the column names, default is 'infer'.
- names: a list of column names to use instead of the names in the CSV file.
- index_col: the column to use as the index of the DataFrame.
- dtype: a dictionary of data types for the columns in the DataFrame.
- skiprows: the number of rows to skip from the beginning of the file.
- na_values: a list of values to be treated as missing values.
- encoding: the encoding of the CSV file.
阅读全文