pd.read_csv usecol
时间: 2023-10-29 16:57:20 浏览: 100
`pd.read_csv` is a function provided by the pandas library in Python, used to read data from a CSV file into a DataFrame. The `usecols` parameter is an optional parameter that allows you to specify which columns from the CSV file you want to read.
You can pass `usecols` as an argument to `pd.read_csv` and provide it with a list of column names or column indices that you want to include in the DataFrame. For example:
```python
import pandas as pd
df = pd.read_csv('data.csv', usecols=['column1', 'column2']) # reading specific columns by name
# or
df = pd.read_csv('data.csv', usecols=[0, 1, 3]) # reading specific columns by index
```
In the above examples, only the columns specified in the `usecols` parameter will be read from the CSV file and stored in the DataFrame.
阅读全文