0

dataframe:

data = {"Category":["Resource","Resource","Resource","Resource"],
    "Item1":["Bandwidth","Bandwidth","Bandwidth","Bandwidth"],
    "Item2":["DC","OC","DC","OC"],
    "Amount":[156.415,396.921,-156.415,-396.921]}
df = pd.DataFrame(data)

df = df.groupby(["Category","Item1"],as_index=False).sum()
print df

get the result:

   Category      Item1        Amount
0  Resource  Bandwidth  5.684342e-14

Why Amount not zero?How can I get the right result?

user2890059
  • 145
  • 1
  • 6
  • It is effectively zero. 5.68 x 10^-14 is a very small number. To see why it is stored like that, see the duplicate. You can round it though it is not required for any operation `df.groupby(["Category","Item1"],as_index=False).sum().round(12)` – ayhan Sep 10 '17 at 12:14
  • AttributeError: 'DataFrame' object has no attribute 'round' – user2890059 Sep 10 '17 at 12:26
  • It was introduced in version 17 and version 17 is pretty old. I'd suggest updating your pandas. – ayhan Sep 10 '17 at 12:38
  • `File "/data/pyrun/lib/python2.7/site-packages/pandas-0.17.1-py2.7-linux-x86_64.egg/pandas/core/frame.py", line 4396, in round new_cols = [np.round(v, decimals) for _, v in self.iteritems()] File "/data/pyrun/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 2640, in round_ return round(decimals, out) File "/data/pyrun/lib/python2.7/site-packages/pandas-0.17.1-py2.7-linux-x86_64.egg/pandas/core/series.py", line 1240, in round result = _values_from_object(self).round(decimals, out=out) TypeError: can't multiply sequence by non-int of type 'float'` – user2890059 Sep 10 '17 at 13:22
  • I will try to other method,thank you ! – user2890059 Sep 10 '17 at 13:23

0 Answers0