Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
1.3k views
in Information Technology by (51.9k points)
closed by

Importing and Exporting Data between CSV Files and DataFrames.

1 Answer

+1 vote
by (49.5k points)
selected by
 
Best answer

We can create a DataFrame by importing data from CSV files where values are separated by commas. Similarly, we can also store or export data in a DataFrame as a .csv file.

Importing a CSV file to a DataFrame

Let us assume that we have the following data in a csv file named ResultData.csv stored in the folder C:/Images. In order to practice the code while we progress, you are suggested to create this csv file using a spreadsheet and save in your computer.

We can load the data from the ResultData.csv file into a DataFrame, say marks using Pandas read_csv() function as shown below:

>>> marks = pd.read_csv("C:/Images/ResultData. 

csv",sep =",", header=0) 

>>> marks

• The first parameter to the read_csv() is the name of the comma separated data file along with its path. 

• The parameter sep specifies whether the values are separated by comma, semicolon, tab, or any other character. The default value for sepis a space. 

• The parameter header specifies the number of the row whose values are to be used as the column names. It also marks the start of the data to be fetched. header = 0 implies that column names are inferred from the first line of the file. By default, header = 0. 

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...