![]() ![]() This method allows you to specify a new name for one or more columns. Let's create an example DataFrame with more than two columns: df = pd. To rename the columns of a DataFrame in Pandas, you can use the DataFrame.rename() method. If you don't use that argument the drop() method will just display what would be the final result, but it won't modify your DataFrame. To remove a column from a DataFrame, you use the drop() method.Īgain, similarly to how the rename() method works, you need to specify the value of the inplace argument as True if you want to modify our DataFrame. Therefore, to change my DataFrame I must use the inplace argument. Image Source: A screenshot of the unchanged DataFrame when the name is called without the inplace argument, Edlitrea If I look at it by calling its name, I will see that my DataFrame still looks like this: Image Source: A screenshot of renaming a column without specifying the inplace argument as True, Edlitera The code above will automatically display the following result: ![]() I will create a DataFrame that contains the starting character of a country name inside the Letter column, and the country name itself in the Country column: country_df = pd.DataFrame() To demonstrate with an example, let's first create a simple DataFrame and then let's add a column to it.
0 Comments
Leave a Reply. |