Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
pandas
communitycreator

What is read_csv in pandas?

AKASH BAJWA

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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
Basic demo code

RELATED TAGS

python
pandas
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring