Pandas: Buffer has wrong number of dimensions

Viewed 5383

The following is my code (only mock up numbers):

import pandas as pd 
d = {'x' : [1,4,6,9],
     'y' : [1,4,6,8]}
df = pd.DataFrame(d)
ct = pd.concat([df.x,
                pd.cut(df.y, bins=2)], axis=1)
gp = ct.groupby('x').y.value_counts().unstack().fillna(0)
print(gp)
print(gp[gp.columns[0]])
gp[gp.columns[0]] = gp[gp.columns[0]]/10

print(gp) gives:

y  (0.993, 4.5]  (4.5, 8.0]
x                          
1           1.0         0.0
4           1.0         0.0
6           0.0         1.0
9           0.0         1.0

print(gp[gp.columns[0]]) gives this:

x
1    1.0
4    1.0
6    0.0
9    0.0
Name: (0.993, 4.5], dtype: float64

But the following line:

gp[gp.columns[0]] = gp[gp.columns[0]]/10

Throws this error:

ValueError: Buffer has wrong number of dimensions (expected 1, got 0)

What is causing this error?

1 Answers
Related