Handling delimiter characters in column data

Sometimes, a column separate character is present as part of the data in one of the columns. This leads to incorrectly parsing data as this would split the column that was supposed to be read as one into two. To avoid such a situation, a quote character should be used around the data in the specified columns. This quote character forces read_csv to ignore the delimiter for the data that's present inside the quote character and not break it into two pieces.

The quote characters can be specified using the quotechar argument of read_csv. For example, consider the following dataset. Here, white space is used as a delimiter and double quotes have been used as a grouping element:

 Usage of quotechar keyword 1—input dataset

To parse this, we would use the following code:

d1 = 
pd.read_csv('t1.txt',index_col=0, delim_whitespace=True,quotechar=""")
d1.head()

We would get the following output:

  

Usage of quotechar keyword 2—output dataset
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.140.111