<jupyter_start><jupyter_text>Updating column names<jupyter_code># Change all columns
df.columns = ["first_name", "last_name", "email"]
df.columns
df.head()
df.columns = [x.upper() for x in df.columns]
df.columns
df.columns = [x.lower() for x in df.columns]
df.columns = df.columns.str.replace(" ","_")
df
# Change some columns
df.rename(columns={"first_name":"first","last_name":"last"}, inplace=True)<jupyter_output><empty_output><jupyter_text>Update values - Always use .loc or .at<jupyter_code># Change a compelete row
df.loc[2] = ["John", "Doe", "<EMAIL>"]
df
# Change some specific values
df.loc[2,["last","email"]] = ["Smith","<EMAIL>"]
df
# Change some specific values
df.at[2,["last","email"]] = ["Doe","<EMAIL>"]
df
filt = (df['email'] == "<EMAIL>")
df[filt]['last'] = "Smith"
df
# It didn't actually update the value. To handle this warning:
df.loc[filt,'last'] = "Smith"
df
df["email"] = df["email"].str.upper()
df
df["email"] = df["email"].str.lower()
df<jupyter_output><empty_output><jupyter_text>apply, map, applymap, replace - methods<jupyter_code># apply call a function on the values on dataframe and series
df["email"].apply(len) # Applying length function to each value of email column/series
def update_email(email):
    return email.upper()
# apply call a function on the values on dataframe and series
df["email"] = df["email"].apply(update_email) # Applying custom function to each value of email column/series
df
# Using lambda functions in apply method
df["email"] = df["email"].apply(lambda x: x.lower())
df
# Apply method on DataFrame - applied to each value in DataFrame

df.apply(len) # It doesn't apply on each value, instead it gave the length of each Series - eaach col has 4 values
df.apply(pd.Series.min)
df.apply(lambda x: x.min())<jupyter_output><empty_output><jupyter_text>applymap - only used for DataFrames - apply to each value of DataFrame<jupyter_code>df.applymap(len)<jupyter_output><empty_output><jupyter_text>map only works on Series<jupyter_code>df
df['first'].map({'Hussam':'Corey', 'Haseeb':'Johny'})
df['first'].replace({'Hussam':'Corey', 'Haseeb':'Johny'})
df
df = pd.read_csv("data/survey_results_public.csv", index_col="Respondent")
schema_df = pd.read_csv("data/survey_results_schema.csv", index_col="Column")
pd.set_option("display.max_columns",85)
pd.set_option("display.max_rows",85)
df.head()
schema_df
df.rename(columns={"ConvertedComp":"SalaryUSD"}, inplace=True)
df.head()
df["Hobbyist"]
df["Hobbyist"] = df["Hobbyist"].map({"Yes":True,"No":False})
df
df["Hobbyist"].value_counts()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17113963438350835, 'fraction_numerical': 0.0031116297160637884, 'mean_word_length': 6.938271604938271, 'pattern_counts': {'":': 5, '<': 25, '<?xml version=': 0, '>': 25, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '663370', 'license': 'MIT', 'n_tokens_mistral': 923, 'n_tokens_neox': 904, 'n_words': 221, 'path': 'Corey Schefer/5- Updating Rows and Columns - Modifying Data Within DataFrames.ipynb', 'repo_name': 'HussamCheema/pandas', 'size': '2617'}