A clean syntax for this kind of "find and replace" uses a dict, as

df.Num_of_employees = df.Num_of_employees.replace({"10-Jan": "1-10",
                                                   "Nov-50": "11-50"})
Answer from miriamsimone on Stack Overflow
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.DataFrame.replace.html
pandas.DataFrame.replace โ€” pandas 3.0.5 documentation
For a DataFrame a dict can specify that different values should be replaced in different columns. For example, {'a': 1, 'b': 'z'} looks for the value 1 in column โ€˜aโ€™ and the value โ€˜zโ€™ in column โ€˜bโ€™ and replaces these values with whatever is specified in value.
Discussions

python - Pandas replacing values on specific columns - Stack Overflow
I am aware of these two similar questions: Pandas replace values Pandas: Replacing column values in dataframe I used a different approach for substituting values from which I think it should be ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Replacing certain values from entire columns of a pandas dataframe
Use the map method https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.map.html More on reddit.com
๐ŸŒ r/learnpython
2
1
June 28, 2021
Best way to replace values in one column from another column in pandas?
No, you shouldn't be looping. You should generally avoid that in Pandas. You can assign directly with loc: df.loc[df['new_items'] != 0, 'old_items'] = df['new_items'] or use an apply function: df['old_items'] = df.apply(lambda row: row['new_items'] if row['new_items'] != 0 else row['old_items']) More on reddit.com
๐ŸŒ r/learnpython
2
1
October 20, 2022
Re-Assign values in a specific dataframe column using .iloc[]
To give us the best chance to help you, please include any relevant code. Note. Do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide ). If you have formatting issues or want to post longer sections of code, please use Repl.it , GitHub or PasteBin . I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
๐ŸŒ r/pythonhelp
2
1
September 16, 2023
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ data analysis โ€บ how-to-replace-values-in-column-based-on-condition-in-pandas
How to Replace Values in Column Based on Condition in Pandas? - GeeksforGeeks
November 15, 2024 - In this article, weโ€™ve explored four effective methods to replace values in a Pandas DataFrame column based on conditions: using loc[], np.where(), masking, and apply() with a lambda function.
๐ŸŒ
Favtutor
favtutor.com โ€บ articles โ€บ pandas-replace-column-values
Pandas DataFrame: Replace Column Values (with code)
December 15, 2023 - The Pandas library provides the .replace() method in Python to replace columns in a DataFrame. The .replace() method is a versatile way to replace values in a Pandas DataFrame. It allows you to specify the column, the value to replace, and the ...
๐ŸŒ
Data to Fish
datatofish.com โ€บ replace-values-pandas-dataframe
How to Replace Values in a pandas DataFrame
# replace one specific value in a column df['column_a'] = df['column_a'].replace("x", "y") # replace multiple values (x, y) with one value (z) in a column df['column_a'] = df['column_a'].replace(["x", "y"], "z") # replace values (w, x) with other values (y, z) in a column df['column_a'] = ...
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ how-to-replace-values-on-specific-columns-in-pandas
How to Replace Values on Specific Columns in Pandas | Saturn Cloud Blog
May 1, 2026 - Replacing missing or NaN values in a specific column is a common data preprocessing task. You can use the .fillna() method to replace NaN values with a specific value: import numpy as np import pandas as pd # Load data into a DataFrame data = { 'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Marie'], 'Age': [25, 30, 35, 40, np.nan], 'City': ['New York', 'Los Angeles', 'San Francisco', 'Chicago', 'Washington'] } df = pd.DataFrame(data) print(df)
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python โ€บ pandas
pandas: Replace values in DataFrame and Series with replace() | note.nkmk.me
January 17, 2024 - In pandas, the replace() method allows you to replace values in DataFrame and Series. It is also possible to replace parts of strings using regular expressions (regex). pandas.DataFrame.replace โ€” pan ...
Find elsewhere
๐ŸŒ
Thinking Neuron
thinkingneuron.com โ€บ home โ€บ finding and replacing values in a pandas data frame
Finding and replacing values in a pandas data frame - Thinking Neuron
September 21, 2020 - For example, replacing all negative values in a column with zero or replacing all the outlier values with a sensible value, etc. If you need to find and replace some specific values in columns then the replace() function.
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ third-party โ€บ pandas โ€บ DataFrame โ€บ replace
Python Pandas DataFrame replace() - Replace Values | Vultr Docs
December 27, 2024 - The value 1 in column 'A' and 5 in column 'B' are replaced with 99. This method allows selective replacement within specific columns.
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ how-to-replace-column-values-in-a-pandas-dataframe
How to Replace Column Values in a Pandas DataFrame | Saturn Cloud Blog
May 1, 2026 - In this article, we explored three common methods: using the .replace() method, using Boolean indexing, and using the .map() method. By understanding these methods, you can choose the best approach for your specific ...
๐ŸŒ
Medium
medium.com โ€บ @whyamit101 โ€บ understanding-pandas-replace-function-c2b0b7709233
Understanding pandas replace() Function | by why amit | Medium
February 10, 2025 - Letโ€™s take a look at how replace() works in different situations: ... If you want to replace one specific value with another, you can just pass those values directly into the function.
๐ŸŒ
Statology
statology.org โ€บ home โ€บ how to replace values in a pandas dataframe (with examples)
How to Replace Values in a Pandas DataFrame (With Examples)
September 27, 2022 - The following code shows how to replace multiple values in an entire pandas DataFrame: #replace 'E' with 'East' and 'W' with 'West' df = df.replace(['E', 'W'],['East', 'West']) #view DataFrame print(df) team division rebounds 0 A East 11 1 A West 8 2 B East 7 3 B East 6 4 B West 6 5 C West 5 6 C East 12 ยท The following code shows how to replace a single value in a single column:
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ pandas โ€บ pandas replace column value in dataframe
Pandas Replace Column Value in DataFrame - Spark By {Examples}
November 7, 2024 - In Pandas library there are several ways to replace or update the column value in DataFarame. Changing the column values is required to curate/clean the
๐ŸŒ
Pandas
pandas.pydata.org โ€บ pandas-docs โ€บ version โ€บ 2.1 โ€บ reference โ€บ api โ€บ pandas.DataFrame.replace.html
pandas.DataFrame.replace โ€” pandas 2.1.4 documentation
For a DataFrame a dict can specify that different values should be replaced in different columns. For example, {'a': 1, 'b': 'z'} looks for the value 1 in column โ€˜aโ€™ and the value โ€˜zโ€™ in column โ€˜bโ€™ and replaces these values with whatever is specified in value.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ pandas โ€บ pandas dataframe replace() โ€“ by examples
Pandas DataFrame replace() - by Examples - Spark By {Examples}
October 10, 2024 - pandas.DataFrame.replace() function is used to replace values in columns (one value with another value on all columns). It is a powerful tool for data
๐ŸŒ
Medium
medium.com โ€บ data-science โ€บ an-easy-way-to-replace-values-in-a-pandas-dataframe-2826bd34e59a
An Easy Way to Replace Values in a Pandas DataFrame | by Byron Dolon | TDS Archive | Medium
July 25, 2021 - To do this, Pandas provides a wide range of methods that you can use to work with columns of all data types in your DataFrames. In this piece, letโ€™s take a look specifically at replacing values and sub-strings within columns in a DataFrame.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ best way to replace values in one column from another column in pandas?
r/learnpython on Reddit: Best way to replace values in one column from another column in pandas?
October 20, 2022 -

Original range:

old_items new_items
item1 item6
item2 0
item3 item7
item4 0
item5 item8

Desired output:

old_items new_items
item6 item6
item2 0
item7 item7
item4 0
item8 item8

My stupid solution:

old_items = list(df['old_items'])
new_items = list(df['new_items'])
proper_items = []

for x in range(len(old_items)):
    if new_items[x] != 0:
        proper_items.append(new_items[x])
    else:
        proper_items.append(old_items[x])

df['old_items'] = proper_items