I am attempting to generate full street corner addresses out of fields taken from a .csv. I am using pandas and have written the following code to achieve this result. I am getting back a TypeError about a float object but none of the fields in my dataframe are floats. I iterated through the fields and printed each column type and they all come back strings.. so I am a bit confused.
Here is the code. Any help would be greatly appreciated and apologies if this is something simple as I am still learning:
import pandas as pd
df_CaveIns = pd.read_csv("DEP_Cave_in_CARs.csv")
df_CaveIns['Address'] = ''
df_CaveIns['Address'].to_string()
boro_key = {
'Q' : 'QUEENS',
'S' : 'STATEN ISLAND',
'M' : 'MANHATTAN',
'B' : 'BROOKLYN',
'X' : 'BRONX'
}
def createAddress(row):
if pd.isnull(row['From_Street_Name']) == False and pd.isnull(row['To_Street_Name']) == False:
boro_code = row['Permit'][0]
if boro_code in boro_key:address = "%s AND %s, %s, NEW YORK" %(str(row['On_Street_Name']).strip(),str(row['To_Street_Name']).strip(),str(boro_key[boro_code]))
#print address
return address
elif pd.isnull(row['From_Street_Name']):
boro_code = row['Permit'][0]
if boro_code in boro_key:address = "%s AND %s, %s, NEW YORK" %(str(row['On_Street_Name']).strip(),str(row['To_Street_Name']).strip(),str(boro_key[boro_code]))
#print address
return address
elif pd.isnull(row['To_Street_Name']):
boro_code = row['Permit'][0]
if boro_code in boro_key:address = "%s AND %s, %s, NEW YORK" %(str(row['On_Street_Name']).strip(),str(row['From_Street_Name']).strip(),str(boro_key[boro_code]))
#print address
return address
else:
return None
df_CaveIns['Address'] = df_CaveIns.apply(createAddress, axis=1)
This is the error I'm getting: TypeError: ("'float' object has no attribute 'getitem'", u'occurred at index 31549')
Can anyone help with this?