-3

[![enter image description here][1]][1]

[![enter image description here][2]][2]

This is my current Dataframe: [1]: https://i.stack.imgur.com/xn6N1.png

This is my expected Output: [2]: https://i.stack.imgur.com/1tMX5.png

  • Please have a look at [How to make good pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and [edit[ your question to include your sample input and expected output as text in the body of the question, not as an image or link, to make a [mcve] – G. Anderson Jul 07 '22 at 16:12

1 Answers1

0
import pandas as pd
import numpy as np

new_data = {
  "Name": [],
  "Code": []
}
for index, row in df.iterrows():
    name = row["Name"]
    code = row["Code"]
    new_data["Name"].append(name)
    if(row["Code"] is np.nan):
        new_data["Code"].append(f"{name}_Deault")
    else: 
        new_data["Code"].append(code)

new_df = pd.DataFrame(new_data)
    

That may work for your case.

Oivalf
  • 154
  • 7