Python/pandas n00b. I have code that is processing event data stored in csv files. Data from df["CONTACT PHONE NUMBER"]
is outputting the phone number as `5555551212.0' Obviously, the ".0" is a problem, but added because it's an integer, I imagine?
Anyhoo, I decided that I should format the phone number for usability's sake.
The number comes from the csv file, unformatted. The number will always be ten digits: 5555551212, but I would like to display it as (555)555-1212.
import glob
import os
import pandas as pd
import sys
csvfiles = os.path.join(directory, '*.csv')
for csvfile in glob.glob(csvfiles):
df = pd.read_csv(filename)
#formatting the contact phone
phone_nos = df["CONTACT PHONE NUMBER"]
for phone_no in phone_nos:
contactphone = "(%c%c%c)%c%c%c-%c%c%c%c" % tuple(map(ord,phone_no))
The last line gives me the following error:
not enough arguments for format string
But maybe this isn't the pandas way of doing this. Since I'm iterating through an array, I also need to save the data in its existing column or rebuild that column after the phone numbers have been processed.