Trusted answers to developer questions

What is read_csv in pandas?

Get Started With Machine Learning

Learn the fundamentals of Machine Learning with this free course. Future-proof your career by adding ML skills to your toolkit — or prepare to land a job in AI or Data Science.

The read_csv() function in pandas helps to read comma-separated values (CSV). It takes multiple arguments. We can simply pass a filename to it, provided pandas code and content file are in the same directory. Otherwise, a complete directory with a file name are required such as: directory\FileName i.e."C:\augmentedReality.csv".

Syntax

import pandas as pd
dataFrame = pd.read_csv("path/filename.csv")

Parameters

There are multiple parameters to this function. The following are some of the frequently used parameters.

Check out this link for the complete documentation.

  • filepath/buffer: A valid path or a URL, but should follow a valid URL schema, i.e., HTTP, FTP, file, etc.
  • sep: string, default (,).
  • delimiter: string, default (none).
  • header: int, list of int, default (first row as column names).
  • names: array (contains column names), optional.

Return value

read.csv() returns either a DataFrame or a TextParser. A CSV file will be turned into a 2D data structure with labeled columns. If names is supplied, labels will be as mentioned.

Code

main.py
File.csv
#Pandas read_csv() function
import pandas as pd
df = pd.read_csv("File.csv")
print(df) #Print File.csv data on console

RELATED TAGS

python
pandas
Did you find this helpful?