/
Chapter- 4  importing/ exporting Data between CSV files / Chapter- 4  importing/ exporting Data between CSV files /

Chapter- 4 importing/ exporting Data between CSV files / - PowerPoint Presentation

susan
susan . @susan
Follow
93 views
Uploaded On 2023-07-23

Chapter- 4 importing/ exporting Data between CSV files / - PPT Presentation

MySQL and Pandas Made by Gayatri Ghadiali we have seen Python Pandas library and learn about two data structures of Pandas library ie series and D ataframes that are capable of storing any types of data in 2D tabular format ID: 1010753

data csv mysql files csv data files mysql file gayatri importing ghadiali pandasmade exporting row format pandas read table

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Chapter- 4 importing/ exporting Data be..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1. Chapter- 4 importing/ exporting Data between CSV files /MySQL and PandasMade by: Gayatri Ghadiali we have seen Python Pandas library and learn about two data structures of Pandas library i.e series and Dataframes, that are capable of storing any types of data in 2D tabular format. we can also use spreadsheet files (Ms excel) or database tables (Mysql/Access) to store the data in 2D table formats. Dataframes can also hold data in similar way, you can transfer data from Data frame to Such data files (or tables) or from files in to a data frame.Two types of transfer of files we have to learn is:To transfer a data to/from a .CSV file from / in to Dataframe. To transfer to/from Database table from/ in to Dataframe.1

2. importing/ exporting Data between CSV files /MySQL and PandasMade by: Gayatri Ghadiali About CSV file:The acronym CSV is short form of comma separated values. The csv format refers to a tabular data that has been saved as plain text where data is separated by commas. e.g. consider a table having some data as shown below if you store this tables data in csv format then the data of the table will be stored in csv format as shown below on the right.NameEmailPhone numberAddressBob Smithbob@example.com123-456-7809123 Fake streetMike Jonesmike@example.com098-765-4321321 Fake avenue2

3. importing/ exporting Data between CSV files /MySQL and PandasMade by: Gayatri Ghadiali  As you can see that in CSV formatEach row of the table is stored in one row i.e. the number of rows in a csv file are equal to number of rows in the table( or sheet or database table etc )The field values of a row are stored  together with commas after every field value; but after the last field’s value in a line /row, no comma is given, just the end of line. The csv format is popular as it offers  following advantages: simple compact and indifferent format for data storage. A common format for data interchange it can be opened in popular spreadsheet packages like MS Excel , calc etc.Nearly all spreadsheets and databases support Import / export to csv format3

4. importing/ exporting Data between CSV files /MySQL and PandasMade by: Gayatri Ghadiali 4Create CSV file:You can create a csv file yourself by saving data of an MS Excel file in csv format using Save As command from file menu and selecting Save As type as csv format.Eg. csv file sample.csv, is shown in notepad as well as in MS Excel.

5. importing/ exporting Data between CSV files /MySQL and PandasMade by: Gayatri Ghadiali 5Reading from a CSV file to Dataframe:You can use read_csv()function to read data from a CSV file in your dataframe.<DF> =pandas.read_csv(filepath)OUTPUTSaved path is E:\sample.csvNote: If you get file path error by single slash then change it to double slashesi.e. “E:\\sample.csv”

6. importing/ exporting Data between CSV files /MySQL and PandasMade by: Gayatri Ghadiali 6If we don’t want the first row to be considered as column headings and want default column heading be added .<DF> =pandas.read_csv(filepath, header=None)OUTPUT

7. importing/ exporting Data between CSV files /MySQL and PandasMade by: Gayatri Ghadiali 7If we have first row having some default column values, that we don’t want as columns value than use skiprows argument.OUTPUTSaved path is E:\student.csv

8. importing/ exporting Data between CSV files /MySQL and PandasMade by: Gayatri Ghadiali 8skiprow argument if given as 1 first row is skipped. OUTPUTSaved path is E:\student.csv

9. importing/ exporting Data between CSV files /MySQL and PandasMade by: Gayatri Ghadiali 9<DF> =pandas.read_csv(filepath, names=<sequence containing column names>,skiprows=<n>)skiprow argument can also take list of row nos. or a row number to skipped rows from the beginning.OUTPUT

10. importing/ exporting Data between CSV files /MySQL and PandasMade by: Gayatri Ghadiali 10Get Dataframe index labels from CSV: OUTPUT<DF> =pandas.read_csv(filepath, index_col=<column name>)

11. importing/ exporting Data between CSV files /MySQL and PandasMade by: Gayatri Ghadiali 11Get Dataframe index labels from CSV: OUTPUT<DF> =pandas.read_csv(filepath, index_col=<column name>)