> ## Content Index
> Fetch the complete content index at: https://datascientyst.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How To Read Only Specific Columns in Pandas read CSV
- URL: https://datascientyst.com/how-to-read-only-specific-columns-in-pandas-read-csv/
- Published: 2023-09-03T09:43:10.000Z
- Updated: 2023-09-03T09:43:10.000Z
- Author: John D K
- Tags: read_csv()

To read only specific columns from CSV file using Pandas read\_csv method we need to use parameter `usecols=fields`

## Steps to read specific columns from CSV file

- Import pandas
- Define columns to be read
- `usecols=fields` \- to list columns to be read  
  - Subset of columns to select, denoted either by column labels or column indices.
- `low_memory = True` \- reading in chunks  
  - Internally process the file in chunks, resulting in lower memory use while parsing, but possibly mixed type inference.
- `index_col` \- to identify column X as index  
  - Column(s) to use as row label(s), denoted either by column labels or column indices.
- `names` and `header` to override the column names.

More information can be found: [DataFrame.plot - secondary\_y](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.html?ref=datascientyst.com)

## Data

Suppose we have the following CSV file which we like to read with Pandas. We want to read only single column from this CSV file into DataFrame:

```bash
,x,y,z
0,a,e,1
1,b,f,2
2,c,g,3
3,d,i,4

```

|   | x | y | z |
| - | - | - | - |
| 0 | a | e | 1 |
| 1 | b | f | 2 |
| 2 | c | g | 3 |
| 3 | d | i | 4 |

## Example

```python
import pandas as pd
cols = ['x', 'y']
df = pd.read_csv('data/data_0.csv', usecols = cols, low_memory = True)

```

## Output

![](https://datascientyst.com/content/images/2023/09/read-only-specific-columns-in-pandas-read-csv.webp)

## Resources

- [pandas.read\_csv](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read%5Fcsv.html?ref=datascientyst.com)