we can use for ip if any body have Any notes you can copy it
Size: 724.44 KB
Language: en
Added: Apr 27, 2024
Slides: 14 pages
Slide Content
Data Transfer Between Files, Databases
and DataFrames
Based on CBSE Curriculum
Class-11
By-
NehaTyagi
PGTCS
KV5JaipurIIShift
JaipurRegion
Neha Tyagi, PGT CS II Shift Jaipur
Data transfer between DataFrames and .CSV file
NehaTyagi, PGT CS II Shift Jaipur
•CSVformatisakindoftabulardataseparatedbycommaand
isstoredintheformofplaintext.
InCSVformat-
•Eachrowofthetableisstoredinonerow.
•Thefield-valesofarowarestoredtogetherwithcommaafter
everyfieldvalue.
AdvantagesofCSVformat-
•Asimple,compactandubiquitousformatfordatastorage.
•Acommonformatfordatainterchange.
•ItcanbeopenedinpopularspredsheetpackageslikeMS-EXCELetc.
•Nearlyallspredsheetsanddatabasessupportimport/exporttocsv
format.
Roll NoNameMarks
101Ramesh77.5
102Harish45.6
Tabular Data
After conversion to CSV Format
Roll No., Name,Marks
101,Ramesh,77.5
102,Harish,45.6
Loading Data from CSV to DataFrame
Neha Tyagi, PGT CS II Shift Jaipur
Emp.csv file , in tabular format Emp.csv file , in Notepad format
Neha Tyagi, PGT CS II Shift Jaipur
importpandasaspd
<DF>=pd.read_csv(<FilePath>)
•Assumethefilepathasc:\data\emp.csvthenfollowingtypeof
filewillbeopened-
Reading from a CSV file to DataFrame
Neha Tyagi, PGT CS II Shift Jaipur
•Ifafiledoesnothavetoprowi.e.Headingsthenitispossible
toprovideheadingsinpython.
Reading from a CSV file to DataFrame
Headings does nt come
from header=None
It takes data by skipping one
row from skiprows = 1
Neha Tyagi, PGT CS II Shift Jaipur
Reading selected lines fron CSV file
Use of nrows= <n>
Reading from CSV file when separator is other than comma
Use of sep= <char>
Neha Tyagi, PGT CS II Shift Jaipur
importpandasaspd
<DF>.to_csv(<FilePath>)
or
<DF>.to_csv(<FilePath>,sep=<char>)
•Supposeourfilepathisc:\data\data.csvthen-
Writing from a DataFrame to CSV file
Here @ is used
as seperator
If there os NaN
values then it is
stored in file as
empty string.
Data transfer between DataFrames and SQL Database
Neha Tyagi, PGT CS II Shift Jaipur
•InthischapterwewilllearnthathowtotransferdatafromSQL
tablewiththehelpofsqlite3libraryofpython.sqlite3comes
inbuiltwithpython.sqlite3librarydealswithSQLitedatabases.
•Usewww.sqlite.org/download.htmltodownloadSqlite3.
•Weworkonsqlite>promptonSqlite3.Itsupportsall
commandsofSQLwhicharesupportedbymysql.
Data transfer between DataFrames and SQL Database
Neha Tyagi, PGT CS II Shift Jaipur
Here sqlite3 is installed.
Creation of table in sqlite3 is shown here.
Data transfer between DataFrames and SQL Database
Neha Tyagi, PGT CS II Shift Jaipur
Data has
transferred to
database from
DataFrame.
Plotting from DataFrames
Neha Tyagi, PGT CS II Shift Jaipur
Use pip installfor installing matplotlib module.
Plotting from DataFrames
Neha Tyagi, PGT CS II Shift Jaipur
Thank you
Please follow us on our blog
Neha Tyagi, KV 5 Jaipur II Shift
www.pythontrends.wordpress.com