Data Transfer Between Files, SQL Databases & Dataframes: Comma To Separate Each Specific Data Value. CSV Advantages
Data Transfer Between Files, SQL Databases & Dataframes: Comma To Separate Each Specific Data Value. CSV Advantages
The structure of a CSV file is given away by its name. Normally, CSV files use a
comma to separate each specific data value.
CSV Advantages
CSV allows moving most basic data only. Complex configurations cannot
be imported and exported this way
There is no distinction between text and numeric values
No standard way to represent binary data
Problems with importing CSV into SQL (no distinction between NULL and
quotes)
Poor support of special characters
No standard way to represent control characters
Lack of universal standard
The CSV file format is not fully standardized. The basic idea of separating fields with
a comma is clear, but that idea gets complicated when the field data may also contain
commas or even embedded line-breaks. CSV implementations may not handle such
field data, or they may use quotation marks to surround the field. Quotation does not
solve everything: some fields may need embedded quotation marks, so a CSV
implementation may include escape characters or escape sequences.
You can then open the file using Microsoft Excel or another spreadsheet
program. It would create a table of data similar to the following:
Note : If the fields of data in your CSV file contain commas, you can protect
them by enclosing those data fields in double quotes (").
1.2 Using Data Frame
(i) pandas.DataFrame.to_csv : (To create CSV from DataFrame)
DataFrame.to_csv(path_or_buf=None, sep=', ', na_rep='', float_format=No
ne, columns=None, header=True,index=True, index_label=None, mode='w'
, encoding=None, compression='infer', quoting=None, quotechar='"',line_te
rminator=None, chunksize=None, tupleize_cols=None, date_format=None,
doublequote=True,escapechar=None, decimal='.')
df = pd.DataFrame(data)
df.to_csv("mycsv.csv")
import pandas as
pd
Here we have made
data = {'Name':['Shraddha', index false
'Shanti','Monica','Yogita'],'Age':[28,34,29,39]}
df = pd.DataFrame(data)
df.to_csv("mycsv1.csv",index=False)
Note here
index is not
appearing
with records
Separator
is replaced
with ;
...........................................
0 1 2
0 Shraddha 28 Gwalior Showing Elements without header
1 Shanti 34 Lucknow
2 Monica 29 Indore
3 Yogita 39 Gwalior
...........................................
Name Age City
0 Shraddha 28 Gwalior Column headings are shown with dataFrame
1 Shanti 34 Lucknow
2 Monica 29 Indore
3 Yogita 39 Gwalior