<jupyter_start><jupyter_text>Filling In Missing Data<jupyter_code>df.fillna(0)
#Calling fillna with a dict, you can use a different fill value for each column:
df.fillna({1: 0.5, 2: 0})
#fillna returns a new object, but you can modify the existing object in-place:
df.fillna(0, inplace=True)
df
df = pd.DataFrame(np.random.randn(6, 3))
df.iloc[2:, 1] = NA
df.iloc[4:, 2] = NA
df
df.fillna(method='ffill')<jupyter_output><empty_output><jupyter_text>Data Transformation  Removing Duplicates<jupyter_code>data = pd.DataFrame({'k1': ['one', 'two'] * 3 + ['two'], 'k2': [1, 1, 2, 3, 3, 4, 4]})
data
data.duplicated()
data.drop_duplicates()
data['v1'] = range(7)
data
data.drop_duplicates(['k1'])
data.drop_duplicates(['k1', 'k2'], keep='last')
data = pd.DataFrame({'food': ['bacon', 'pulled pork', 'bacon',
    'Pastrami', 'corned beef', 'Bacon',
    'pastrami', 'honey ham', 'nova lox'],
    'ounces': [4, 3, 12, 6, 7.5, 8, 3, 5, 6]})
meat_to_animal = {
 'bacon': 'pig',
 'pulled pork': 'pig',
 'pastrami': 'cow',
 'corned beef': 'cow',
 'honey ham': 'pig',
 'nova lox': 'salmon'
}
lowercased = data['food'].str.lower()
lowercased
data['animal'] = lowercased.map(meat_to_animal)
data
data['food'].map(lambda x: meat_to_animal[x.lower()])<jupyter_output><empty_output><jupyter_text>Replacing Values<jupyter_code>data = pd.Series([1., -999., 2., -999., -1000., 3.])
data.replace(-999, NA)<jupyter_output><empty_output><jupyter_text>Renaming Axis Indexes<jupyter_code>data = pd.DataFrame(np.arange(12).reshape((3, 4)),
    index=['Ohio', 'Colorado', 'New York'],
    columns=['one', 'two', 'three', 'four'])
transform = lambda x: x[:4].upper()
data.index.map(transform)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20685579196217493, 'fraction_numerical': 0.03546099290780142, 'mean_word_length': 6.143459915611814, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '477053', 'license': 'Unlicense', 'n_tokens_mistral': 748, 'n_tokens_neox': 698, 'n_words': 153, 'path': 'Class Work/class 7 - Data Cleaning.ipynb', 'repo_name': 'shkhaider2015/PIAIC-QUARTER-2', 'size': '1692'}