get a column of a csv python 1

get a column of a csv python

df = pd.read_csv("sample_file.csv", usecols=["name_of_col1", "name_of_col2"])

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 name of the csv file as a parameter to the read_csv() method.
3. We are passing the usecols parameter to the read_csv() method.
4. We are passing the list of column names as a parameter to the usecols parameter.
5. We are storing the dataframe in a variable called df.

Similar Posts