Reputation: 331
I have got a Pandas dataframe where the column indices are tuples of size 3. I noticed some of them are only of size 2 and have missed a value. I have been trying to rename those columns by doing so:
for x in df.columns:
if len(x) == 2:
y = list(x)
y.insert(1, 'missing_str')
df.rename(columns={x, tuple(y)}, inplace=True)
However, I got a TypeError: 'set' object is not callable.
Would appreciate any help to solve with the problem.
Upvotes: 0
Views: 227
Reputation: 6642
pandas.DataFrame.rename(columns=...)
requires a dict or a function. You are providing a set. Did you mean {x: tuple(y)}
?
Upvotes: 2