0

I have a dataset where the part numbers are categorized into subinventories.

I want to replace some values, e.g. "COIL 8" with just "COIL", so I can group similar parts together. The data is an object in the dataframe. I've stripped out leading and trailing spaces. I've also copied the value from the dataframe into the code to make sure the number of spaces between COIL and 8 is the same. Changing the Subinventory to "COIL_8" is not an option...that's how I receive the data. I only need to change the values in the "Subinventory" column but there isn't an issue with code applying to the entire dataframe.

I've looked in documentation and tried several of the options but not getting something correct as none of the values are replaced.

elemental_inv_df.replace({'Subinventory': 'COIL 8'}, {'Subinventory': 'COIL'}, regex=True, inplace = True)
elemental_inv_df = elemental_inv_df.replace("FAB 1", "FAB")
elemental_inv_df = elemental_inv_df.replace(regex={'COIL 33': 'COIL'})
elemental_inv_df = elemental_inv_df.replace(['DECOIL 1'], 'DECOIL')

elemental_inv_df

enter image description here

1 Answer 1

1

Basically you're replacing, but not saving the change.

Try :

elemental_inv_df.replace({'Subinventory': 'COIL 8'}, {'Subinventory': 'COIL'}, regex=True, inplace = True)

or

   elemental_inv_df = elemental_inv_df.replace({'Subinventory': 'COIL 8'}, {'Subinventory': 'COIL'}, regex=True)

Edit :

You need to check the actual value you're trying to replace, by checking

elemental_inv_df.Subinventory

output

0               FAB
1     COIL        8
2            DECOIL
3     COIL       33
4            DECOIL
5     FAB         1
6               FAB
7     COIL       12
8     DECOIL      1
9               FAB
10           DECOIL
11    COIL       27
12           DECOIL
13              FAB
14    COIL        7
15           DECOIL
16              FAB
17              FAB
18        RUAN-RCVD
19              FAB
20              FAB
21              FAB
22              FAB
23              FAB
24              FAB
25              FAB
26              FAB
27              FAB
28              FAB

So it's not

"COIL 8" but "COIL        8" you need to replace.
Sign up to request clarification or add additional context in comments.

7 Comments

Hmmm, well, I altered code but have the same result...I appreciate your assistance...edited original image to reflect changes...
Can you do elemental_inv_df .head().to_clipboard() then paste it into your post so we can test it ourselve ?
I've uploaded the Jupyter Notebook and Data files at github.com/danawoodruff/Inventory.git. Thank you for helping me...I'm not quite getting this.
I've been using Google Colab. The Excel file opens in the Jupyter Notebook or as an Excel file on desktop...not certain why you'd get corruption messgae. I've reloaded it to Github, apologies.
I found your problem, basically you think it's "COIL 8" but in fact it's "COIL 8", hum we don't see it here, but it's a lot more " " than one.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.