Why is there a "TypeError: incompatible index of inserted column with frame index" error in Pandas version 2.0.0 only

jjudge3

Complete newb here, for asking questions on this platform as well as python development.

I was given a script and there is a line of code that works with Pandas 1.4.4, but not Pandas 2.0.0.

The line of code is:

CLEANCPM.groupby(['UNIT_NUM'])['COST'].apply(lambda x:x.cumsum())

When I force install pandas v1.4.4, the script completes without error.

When using Pandas 2.0.0, I get:

"TypeError: incompatible index of inserted column with frame index"

I created a virtual environment and installed Pandas v1.4.4. This is the version that is in the Ananconda distribution I was originally using to run this script in a Jupyter notebook.

When I tried using VSCode and installed Pandas, version 2.0.0 was installed. Then the error started.

I know enough that certain package versions are necessary and that's the point of virtual environments.

Just wondering if I should post an issue on github for this. I found similar looking issue posts, but thought they may be for older (than 1.4.4) pandas versions.

mozway

You probably shouldn't use apply+cumsum. You can directly use groupby.cumsum:

CLEANCPM.groupby(['UNIT_NUM'])['COST'].cumsum()

Unlike apply, this will handle the index differently, leaving it unchanged.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why is (2^31) >> 32 not 0?

Mongorestore: createIndex error: Values in v:2 index key pattern cannot be of type object. Only numbers > 0, numbers < 0, and strings are allowed

why matplotlib give the error [<matplotlib.lines.Line2D object at 0x0392A9D0>]?

Why is '' > 0 True in Python 2?

Why GoConvey Tests fail with error code 0?

Why is x[0] != x[0][0] != x[0][0][0]?

CGContextSaveGState: invalid context 0x0 Error only on device

Why is calc(50% + 0) an error?

Why does OpenCV cap.get(cv2.CAP_PROP_POS_MSEC) only return 0?

Why is 0 divided by 0 throwing an overflow error in VBA?

Python/Pandas Subtract Only if Value is not 0

Pandas groupby selecting only one value based on 2 groups and converting rest to 0

Why is 2 ** (1 << 31) == 0?

How to assign Pandas.Series.str.extractall() result back to original dataset? (TypeError: incompatible index of inserted column with frame index)

Why the warning "Selector specificity 0, 2, 0"?

Why is [0] === [0] false

Why variable y is 0, is not 2?

Pandas groupby selecting only two values based on 2 groups and converting rest to 0

Pandas Dataframe concat: is it correct to understand append as a simplified version of concat with few kwargs and can only operate on axis=0

Error message of 'ValueError: int() base must be >= 2 and <= 36, or 0' why?

Why do I get error "ArrayIndexOutOfBoundsException: length=0; index=0"?

Why only codeblocks give me return error(0xc00000FD)?

Why `+0n` throws an error but `-0n` does not?

Replace 0 with NaN for selected columns only if all values are 0 in Pandas

Why is 2 not > 0 ?? It is instead <= 0, but not < 0, nor == 0

why only the index 0 changes him value to ""

I can only slice my pandas dataframe with a slicing window such as [0:1] to get a specific row, doing [0 raises a KeyError why?

when using group_by: TypeError: incompatible index of inserted column with frame index

Why i am using Random.range(0,2) and only generate me the number 0?