read_csv only certain columns 1

read_csv only certain columns

col_list = ["Name", "Department"]
df = pd.read_csv("sample_file.csv", usecols=col_list)

Here is what the above code is Doing:
1. We are reading the csv file using the read_csv() method.
2. We are passing the usecols parameter with a list of column names.
3. The read_csv() method will read only the columns that are specified in the list.

Similar Posts