Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Why the DataFrame loaded from sms_spam_collection/SMSSpamCollection.tsv has fewer lines than that file. #757

sammyne started this conversation in General
Discussion options

I'm playing around the chapter06's notebook, and find

  • sms_spam_collection/SMSSpamCollection.tsv has 5574 lines
  • but the DataFrame loaded from it has only 5572 lines

Just wonder what causes the mismatch~

image
You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

Hi @sammyne

Good catch. The quote on line 5082 on SMSSpamCollection.tsv is causing the problem. This results in the following lines 5083 and 5084 to be parsed together by pandas read_csv. I looked at the data and there are several instances of single quotation marks ", however line 5082 is the only offending one.

There's a few solutions:

  1. Remove the quotation marker in line 5082 only.
  2. Look at the pandas documentation here and use the quoting control field with csv.QUOTE_NONE from these docs:

df = pd.read_csv(data_file_path, sep='\t', header=None, names=["Label", "Text"], quoting=3)

  1. Normalize text file by removing quotation marks
  2. Read file using python open() manually and handle quotation markers by your choosing
You must be logged in to vote
1 reply
Comment options

Good catch actually. I didn't see that issue before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /