I have a pandas Series:
freq_features = num_occurrences/num_nodes
print(type(freq_features))
print(freq_features)
<class 'pandas.core.series.Series'>
PAT 0.386667
NUR 0.360000
MED 0.146667
ADM 0.106667
I round each value to 2 decimal places:
freq_features_rounded = freq_features.round(2)
print type(freq_features_rounded)
print freq_features_rounded
<class 'pandas.core.series.Series'>
PAT 0.39
NUR 0.36
MED 0.15
ADM 0.11
dtype: float64
But when I use the to_dict()
command, I get the non-rounded values (except for the ADM
key):
freq_features_dict = freq_features_rounded.to_dict()
print freq_features_dict
{'NUR': 0.35999999999999999, 'ADM': 0.11, 'PAT': 0.39000000000000001, 'MED': 0.14999999999999999}
Why is this happening, and how can I get my rounded values into the dict()
object as values?