SlideShare uma empresa Scribd logo
1 de 18
Guided Discovery of
interfacing CSV files with
Python
Pandas DataFrame and CSV files: Interfacing
This Photo by Unknown Author is licensed under CC BY-SA
• Pandas DataFrame is a two dimensional
structures with row and columns.
• Due to its inherent tabular structure, we
can query and run calculations on pandas
dataframes across an entire row, an entire
column, or a specific cell or series of cells
based on either location and attribute
values.
• CSV files are a very common file format
used to collect and organize scientific
data.
• CSV files use commas (or some other
delimiter like tab spaces or semi-colons)
to indicate separate values.
• CSV files also support labeled names for
the columns, referred to as headers. This
means that CSV files can easily support
multiple columns of related data.
This Photo by Unknown Author
is licensed under CC BY-SA
CSV files: Comma Separated Files
We will learn how to import tabular data from text files (.csv) into pandas
dataframes, so we can take advantage of the benefits of working with pandas
dataframes.
Statistical
functions
Data
Analysis
Why interface CSV with Python Pandas?
Importing CSV files using Pandas DataFrame
import pandas as pd
result = pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv")
print(result)
Command to read a CSV file
Storage path of the file
Data Frame
Output
read_csv : Syntax
DataFrame = pd.read_csv (“filepath”, sep=“ “, header=0)
• name of the comma separated data file along with its path.
• sep specifies whether the values are separated by comma, semicolon, tab, or any
other character. The default value for sep is a space.
• 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. By default,
header=0.
1 2 3
1
2
3
Variation in sep parameter
import pandas as pd
result = pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv“, sep=“,”,
header=0)
print(result)
Output
Variation in the header parameter
import pandas as pd
result = pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv“, sep=“,”,
header=1)
print(result)
Output
Using the Name parameter
We can specify our own column names using the parameter names while creating
the DataFrame using the read_csv() function.
import pandas as pd
result=pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv", header=0,
names=["Roll_no","Studname", "Math","English","Science", "Arts"])
print(result)
Note: We need to specify the
Header=0 parameter here otherwise,
there will be a double heading.
Output
Changing Index column
import pandas as pd
result=pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv",
index_col='Enroll_no')
print(result)
Output
Using DataFrame functions
import pandas as pd
result=pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv")
print(result.head(2))
print(result.tail(2))
Output
Applying Pandas Aggregate Functions
import pandas as pd
result=pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv")
print(result.sum())
print(result.sum(axis=1))
print(result['Marks1'].sum())
print(result[‘Marks1’])
print(result.mean())
print(result.loc[2])
print(result.loc[1:4])
Applying Pandas Aggregate Functions
Adding a new column
import pandas as pd
result=pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv")
result["Marks6"]=[22,11,13,15]
print(result)
Output
Adding a new row
import pandas as pd
result=pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv")
result.loc[4]=[22,24,25,20.20]
print(result)
Output
Exporting DataFrames to CSV
import pandas as pd
marksUT= {'Name':['Raman','Zuhaire','Mishti','Drovya'],
'UT':[1,2,3,4],
'Maths':[22,21,14,20],
'Science':[25,22,21,18],
'S.St':[18,17,15,22],
'Hindi':[20,22,15,17],
'Eng':[24,23,13,20]
}
pd1=pd.DataFrame(marksUT)
pd1.to_csv(path_or_buf='C:/Users/Neeru/Desktop/Docs/dd.csv’,
sep=',')
DataFrame
Creation
File PathCommand to write to a CSV file
The to_csv command
DataFrame.to_csv(path_or_buf=“File path”, sep=',')
• name of the comma separated data file along with its path.
• sep specifies that the values are separated by a comma.2
21
1
Attendance link
docs.google.com/forms/d/e/1FAIpQLSdTbUb1khFFMxh6di8G8mpbrfrh98ppn0poOdQDypmchq741Q/
viewform?vc=0&c=0&w=1

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

C programming - String
C programming - StringC programming - String
C programming - String
 
Perl Programming - 01 Basic Perl
Perl Programming - 01 Basic PerlPerl Programming - 01 Basic Perl
Perl Programming - 01 Basic Perl
 
The string class
The string classThe string class
The string class
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
Function in c
Function in cFunction in c
Function in c
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
C# File IO Operations
C# File IO OperationsC# File IO Operations
C# File IO Operations
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statements
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
Python sqlite3
Python sqlite3Python sqlite3
Python sqlite3
 
Python - Lecture 11
Python - Lecture 11Python - Lecture 11
Python - Lecture 11
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
 
Textbox n label
Textbox n labelTextbox n label
Textbox n label
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
Autoboxing And Unboxing In Java
Autoboxing And Unboxing In JavaAutoboxing And Unboxing In Java
Autoboxing And Unboxing In Java
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
 

Semelhante a Python and CSV Connectivity

Pandas Dataframe reading data Kirti final.pptx
Pandas Dataframe reading data  Kirti final.pptxPandas Dataframe reading data  Kirti final.pptx
Pandas Dataframe reading data Kirti final.pptxKirti Verma
 
Introduction to sas
Introduction to sasIntroduction to sas
Introduction to sasAjay Ohri
 
Data Migration with Spark to Hive
Data Migration with Spark to HiveData Migration with Spark to Hive
Data Migration with Spark to HiveDatabricks
 
Azure Data Factory Data Flows Training (Sept 2020 Update)
Azure Data Factory Data Flows Training (Sept 2020 Update)Azure Data Factory Data Flows Training (Sept 2020 Update)
Azure Data Factory Data Flows Training (Sept 2020 Update)Mark Kromer
 
Reading_csv.pptx
Reading_csv.pptxReading_csv.pptx
Reading_csv.pptxOpOp39
 
Dealing with files in python specially CSV files
Dealing with files in python specially CSV filesDealing with files in python specially CSV files
Dealing with files in python specially CSV filesKiran Kumaraswamy
 
Introduction to-sas-1211594349119006-8
Introduction to-sas-1211594349119006-8Introduction to-sas-1211594349119006-8
Introduction to-sas-1211594349119006-8thotakoti
 
Python Pandas.pptx
Python Pandas.pptxPython Pandas.pptx
Python Pandas.pptxSujayaBiju
 
Ten tools for ten big data areas 04_Apache Hive
Ten tools for ten big data areas 04_Apache HiveTen tools for ten big data areas 04_Apache Hive
Ten tools for ten big data areas 04_Apache HiveWill Du
 
Pandas-(Ziad).pptx
Pandas-(Ziad).pptxPandas-(Ziad).pptx
Pandas-(Ziad).pptxSivam Chinna
 
BAS 150 Lesson 4 Lecture
BAS 150 Lesson 4 LectureBAS 150 Lesson 4 Lecture
BAS 150 Lesson 4 LectureWake Tech BAS
 
Mapping Data Flows Training April 2021
Mapping Data Flows Training April 2021Mapping Data Flows Training April 2021
Mapping Data Flows Training April 2021Mark Kromer
 
Machine learning session 3
Machine learning session 3Machine learning session 3
Machine learning session 3NirsandhG
 
Tabular Data on the Web
Tabular Data on the WebTabular Data on the Web
Tabular Data on the WebGregg Kellogg
 

Semelhante a Python and CSV Connectivity (20)

SAS - Training
SAS - Training SAS - Training
SAS - Training
 
Pandas Dataframe reading data Kirti final.pptx
Pandas Dataframe reading data  Kirti final.pptxPandas Dataframe reading data  Kirti final.pptx
Pandas Dataframe reading data Kirti final.pptx
 
Pa2 session 2
Pa2 session 2Pa2 session 2
Pa2 session 2
 
Introduction to sas
Introduction to sasIntroduction to sas
Introduction to sas
 
Data Migration with Spark to Hive
Data Migration with Spark to HiveData Migration with Spark to Hive
Data Migration with Spark to Hive
 
Azure Data Factory Data Flows Training (Sept 2020 Update)
Azure Data Factory Data Flows Training (Sept 2020 Update)Azure Data Factory Data Flows Training (Sept 2020 Update)
Azure Data Factory Data Flows Training (Sept 2020 Update)
 
Reading_csv.pptx
Reading_csv.pptxReading_csv.pptx
Reading_csv.pptx
 
CSV Files-1.pdf
CSV Files-1.pdfCSV Files-1.pdf
CSV Files-1.pdf
 
Pa1 session 5
Pa1 session 5Pa1 session 5
Pa1 session 5
 
Dealing with files in python specially CSV files
Dealing with files in python specially CSV filesDealing with files in python specially CSV files
Dealing with files in python specially CSV files
 
Moving Data to and From R
Moving Data to and From RMoving Data to and From R
Moving Data to and From R
 
Introduction to-sas-1211594349119006-8
Introduction to-sas-1211594349119006-8Introduction to-sas-1211594349119006-8
Introduction to-sas-1211594349119006-8
 
Python Pandas.pptx
Python Pandas.pptxPython Pandas.pptx
Python Pandas.pptx
 
Ten tools for ten big data areas 04_Apache Hive
Ten tools for ten big data areas 04_Apache HiveTen tools for ten big data areas 04_Apache Hive
Ten tools for ten big data areas 04_Apache Hive
 
Pandas-(Ziad).pptx
Pandas-(Ziad).pptxPandas-(Ziad).pptx
Pandas-(Ziad).pptx
 
CSV_FILES.pptx
CSV_FILES.pptxCSV_FILES.pptx
CSV_FILES.pptx
 
BAS 150 Lesson 4 Lecture
BAS 150 Lesson 4 LectureBAS 150 Lesson 4 Lecture
BAS 150 Lesson 4 Lecture
 
Mapping Data Flows Training April 2021
Mapping Data Flows Training April 2021Mapping Data Flows Training April 2021
Mapping Data Flows Training April 2021
 
Machine learning session 3
Machine learning session 3Machine learning session 3
Machine learning session 3
 
Tabular Data on the Web
Tabular Data on the WebTabular Data on the Web
Tabular Data on the Web
 

Mais de Neeru Mittal

Introduction to AI and its domains.pptx
Introduction to AI and its domains.pptxIntroduction to AI and its domains.pptx
Introduction to AI and its domains.pptxNeeru Mittal
 
Brain Storming techniques in Python
Brain Storming techniques in PythonBrain Storming techniques in Python
Brain Storming techniques in PythonNeeru Mittal
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python PandasNeeru Mittal
 
Python Tips and Tricks
Python Tips and TricksPython Tips and Tricks
Python Tips and TricksNeeru Mittal
 
Working of while loop
Working of while loopWorking of while loop
Working of while loopNeeru Mittal
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++Neeru Mittal
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++Neeru Mittal
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arraysNeeru Mittal
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingNeeru Mittal
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++Neeru Mittal
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programmingNeeru Mittal
 
Getting started in c++
Getting started in c++Getting started in c++
Getting started in c++Neeru Mittal
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Neeru Mittal
 

Mais de Neeru Mittal (18)

Machine Learning
Machine LearningMachine Learning
Machine Learning
 
Introduction to AI and its domains.pptx
Introduction to AI and its domains.pptxIntroduction to AI and its domains.pptx
Introduction to AI and its domains.pptx
 
Brain Storming techniques in Python
Brain Storming techniques in PythonBrain Storming techniques in Python
Brain Storming techniques in Python
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python Pandas
 
Python Tips and Tricks
Python Tips and TricksPython Tips and Tricks
Python Tips and Tricks
 
Working of while loop
Working of while loopWorking of while loop
Working of while loop
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
 
Arrays
ArraysArrays
Arrays
 
Nested loops
Nested loopsNested loops
Nested loops
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Getting started in c++
Getting started in c++Getting started in c++
Getting started in c++
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 

Último

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 

Último (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 

Python and CSV Connectivity

  • 1. Guided Discovery of interfacing CSV files with Python
  • 2. Pandas DataFrame and CSV files: Interfacing This Photo by Unknown Author is licensed under CC BY-SA • Pandas DataFrame is a two dimensional structures with row and columns. • Due to its inherent tabular structure, we can query and run calculations on pandas dataframes across an entire row, an entire column, or a specific cell or series of cells based on either location and attribute values. • CSV files are a very common file format used to collect and organize scientific data. • CSV files use commas (or some other delimiter like tab spaces or semi-colons) to indicate separate values. • CSV files also support labeled names for the columns, referred to as headers. This means that CSV files can easily support multiple columns of related data. This Photo by Unknown Author is licensed under CC BY-SA
  • 3. CSV files: Comma Separated Files We will learn how to import tabular data from text files (.csv) into pandas dataframes, so we can take advantage of the benefits of working with pandas dataframes.
  • 5. Importing CSV files using Pandas DataFrame import pandas as pd result = pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv") print(result) Command to read a CSV file Storage path of the file Data Frame Output
  • 6. read_csv : Syntax DataFrame = pd.read_csv (“filepath”, sep=“ “, header=0) • name of the comma separated data file along with its path. • sep specifies whether the values are separated by comma, semicolon, tab, or any other character. The default value for sep is a space. • 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. By default, header=0. 1 2 3 1 2 3
  • 7. Variation in sep parameter import pandas as pd result = pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv“, sep=“,”, header=0) print(result) Output
  • 8. Variation in the header parameter import pandas as pd result = pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv“, sep=“,”, header=1) print(result) Output
  • 9. Using the Name parameter We can specify our own column names using the parameter names while creating the DataFrame using the read_csv() function. import pandas as pd result=pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv", header=0, names=["Roll_no","Studname", "Math","English","Science", "Arts"]) print(result) Note: We need to specify the Header=0 parameter here otherwise, there will be a double heading. Output
  • 10. Changing Index column import pandas as pd result=pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv", index_col='Enroll_no') print(result) Output
  • 11. Using DataFrame functions import pandas as pd result=pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv") print(result.head(2)) print(result.tail(2)) Output
  • 12. Applying Pandas Aggregate Functions import pandas as pd result=pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv") print(result.sum()) print(result.sum(axis=1)) print(result['Marks1'].sum()) print(result[‘Marks1’])
  • 14. Adding a new column import pandas as pd result=pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv") result["Marks6"]=[22,11,13,15] print(result) Output
  • 15. Adding a new row import pandas as pd result=pd.read_csv ("C:/Users/Neeru/Desktop/Docs/b.csv") result.loc[4]=[22,24,25,20.20] print(result) Output
  • 16. Exporting DataFrames to CSV import pandas as pd marksUT= {'Name':['Raman','Zuhaire','Mishti','Drovya'], 'UT':[1,2,3,4], 'Maths':[22,21,14,20], 'Science':[25,22,21,18], 'S.St':[18,17,15,22], 'Hindi':[20,22,15,17], 'Eng':[24,23,13,20] } pd1=pd.DataFrame(marksUT) pd1.to_csv(path_or_buf='C:/Users/Neeru/Desktop/Docs/dd.csv’, sep=',') DataFrame Creation File PathCommand to write to a CSV file
  • 17. The to_csv command DataFrame.to_csv(path_or_buf=“File path”, sep=',') • name of the comma separated data file along with its path. • sep specifies that the values are separated by a comma.2 21 1