<jupyter_start><jupyter_text>Replacing values<jupyter_code>import pandas as pd
raw_data = {'citi':['a','b','c','d'],
            'rank':[1,2,3,4],
            'score':[11,12,13,14]
           }
data = pd.DataFrame(raw_data, 
                    index = pd.Index([1,2,3,4], name = 'Numbers'),
                    columns = pd.Index(['citi','rank','score'], name = 'Attributes')) 
data
data['citi']
data.replace('c','x')
data.replace([11,12,13,14],[110,120,130,140], inplace=True)
data
data.iloc[2][2]
# lets duplicate some data
data.replace([130,140],[120,120], inplace=True)
data.score.duplicated()
data.score.duplicated().sum()
d2 = data.append({'citi':'d','rank':4,'score':120}, ignore_index=True)
data
d2
d2.duplicated()
d2.loc[d2.duplicated()]
d2.loc[d2.duplicated(keep='first')]
d3 = d2.drop_duplicates()
print(d2)
print(d3)
d4 = d3.append({'citi':'d','rank':4,'score':110},ignore_index=True)
d4
d4.duplicated(subset=['citi','rank'])
d4.drop_duplicates(subset=['citi','rank'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.228486646884273, 'fraction_numerical': 0.07319485657764589, 'mean_word_length': 5.285714285714286, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '163069', 'license': 'Apache-2.0', 'n_tokens_mistral': 440, 'n_tokens_neox': 402, 'n_words': 51, 'path': 'pandas/replacing_values_01.ipynb', 'repo_name': 'dantohe/Springboard', 'size': '1011'}