READING CSV FILES IN PANDAS
Pandas provides the read_csv() method for reading the contents of CSV files. For example, Listing B.6 shows the contents of sometext.csv that contain labeled data (spam or ham), and Listing B.7 shows the contents of read_csv_file.py that illustrates how to read the contents of a CSV file.
Listing B.6: sometext.csv
type text ham Available only for today ham I'm joking with you spam Free entry in 2 a wkly comp ham U dun say so early hor ham I don't think he goes to usf spam FreeMsg Hey there ham my brother is not sick ham As per your request Melle spam WINNER!! As a valued customer
Listing B.7: read_csv_file.py
import pandas as pd
import numpy as np
df = pd.read_csv('sometext.csv', delimiter='\t')
print("=> First five rows:")
print(df.head(5))
Listing B.7 reads the contents of sometext.csv, and the columns are separated by a tab (“\t”) delimiter. Launch the code in...