I am trying to write data that is stored in a python dictionary to a csv file. For some reason the last 15 lines or so don't end up in the csv file. The python dictionary is formatted like this:
{name:{key1:value1,key2:value2},
name:{key1:value1,key2:value2},
name:{key1:value1,key2:value2},
name:{key1:value1,key2:value2,key3:value3},
}
I got this to work right before so I know its possible, I just don't remember what I did.
Here is my code:
featuresq =['name',
'to_messages',
'deferral_payments',
'expenses',
'poi',
'deferred_income',
'email_address',
'long_term_incentive',
'restricted_stock_deferred',
'shared_receipt_with_poi',
'loan_advances',
'from_messages',
'other',
'director_fees',
'bonus',
'total_stock_value',
'from_poi_to_this_person',
'from_this_person_to_poi',
'restricted_stock',
'salary',
'total_payments',
'exercised_stock_options']
for name,line in data_dict.items():
line["name"]=name
row=[]
for feature in featuresq:
# if feature in line.keys():\
try:
row.append(line[feature])
# else:
except:
row.append(float('NaN'))
f.writerow(row)