<jupyter_start><jupyter_text>![title](img/cover4.png) Copyright! This material is protected, please do not copy or distribute.    by:<NAME> ***Udemy course : Python Bootcamp for Data Science 2021 Numpy Pandas & Seaborn ***  9.6 Renaming columns and index labels First we import numpy and pandas libraries:<jupyter_code>import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>Here we creat a simple dataframe using the function **pd.DataFrame()**:<jupyter_code>data = pd.DataFrame(np.arange(12).reshape((4, 3)),
 index=['green', 'red', 'black', 'white'],
 columns=['one', 'two', 'three'])
data<jupyter_output><empty_output><jupyter_text>We can rename any index value using the function **rename()**, here green is replaced by yellow:<jupyter_code>data.rename(index = {'green':'yellow'}, inplace =True)
data<jupyter_output><empty_output><jupyter_text>We can aslo replace columns labeles using the same function but adding the argument **columns**, here we replace the column ('three') to be ('four'):<jupyter_code>data.rename(columns = {'three':'four'}, inplace =True)
data<jupyter_output><empty_output><jupyter_text>We can aslo change the format of the labels, for example here we change the index labels to have capital letters using the function **str.upper()**<jupyter_code>data.index = data.index.str.upper()
data<jupyter_output><empty_output><jupyter_text>Similarly, we can change the format of columns labels to a title format using **str.title()**<jupyter_code>data.columns= data.columns.str.title()
data<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12707535121328226, 'fraction_numerical': 0.0070242656449553, 'mean_word_length': 7.516304347826087, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '424224', 'license': 'MIT', 'n_tokens_mistral': 499, 'n_tokens_neox': 488, 'n_words': 151, 'path': '9.6 Renaming columns and index labels.ipynb', 'repo_name': 'SiamakMushakhian/Numpy-Pandas-Seaborn', 'size': '1571'}