I have a CSV with cluters and their latitude/longitudes like this:
cluster_label,latitude,longitude
0,39.18193382,-77.51885109
1,39.18,-77.27
2,39.17917928,-76.6688633
3,39.1782,-77.2617
4,39.1765,-77.1927
I am trying to convert them into a dictionary using Pandas such as this:
{u'0': [39.18193382,-77.51885109],
u'1': [39.18,-77.27],
u'2': [39.17917928,-76.6688633],
u'3': [39.1782,-77.2617],
u'4': [39.1765,-77.1927],}
I have converted into a dictionary using .T.to_dict() but when I try to write out to a new file I get Attribute Error(s):'dict' object has no attribute 'to_csv/json/etc.'. How can I convert my csv file to a dictionary and then save the resulting dictionary as a new file?
Code
import pandas as pd
data = pd.read_csv('cluster_centroids.csv', delimiter=',', index_col='cluster_label')
dict = data.T.to_dict()
dict.to_csv('centroidDict.csv')