If we want to delete the column from DataFrame then we use 1.drop ...

[Pages:6]How to remove/delete/drop the column from DataFrame: -

HOME PAGE

If we want to delete the column from DataFrame then we use following ways: -

1.drop() function

2. pop() function

3. del statement

1. drop() function: - drop() function can be used to remove column from DataFrame and drop() function comes from DataFrame it means drop() function will be accessible by DataFrame object.

Under drop() function we will mention three arguments/parameters i.e. column_label , axis and inplace=True.

1. Column_label means the name of column that we want to remove.

2. axis parameter value can be 0 or 1 that will define at which axis of DataFrame we want to apply the operation, while removing the column, axis value should be one i.e. axis=1.

3. inplace = True , should be mention under drop() function that will delete column permanently from DataFrame.

Syntax to remove the column from DataFrame using drop() function:

Label of column that we want to remove from DataFrame.

Axis=1 , means we are removing column of DataFrame.

DataFrame_object . drop(column_label , axis=1 , inplace=True)

inplace=True , will remove the column permanently from DataFrame.

Note : - 1. drop() function can also be used to remove the column from DataFrame then axis value should be 1 i.e. axis=1. 2. to remove multiple columns from DataFrame using drop() function we will mention column label in list form. 3. axis=1 , means column wise operation on DataFrame . 4. axis=0 means row wise operation.

Example 1 to remove the column from DataFrame using drop() function:-

Remove the column `points1' from DataFrame.

OUTPUT: -

Column `points1' will be deleted from DataFrame.

Example 2 to remove the column from DataFrame using drop() function:-

Remove the column `Unit Test 1' from DataFrame.

OUTPUT: -

Column `UT1' will be deleted from DataFrame.

How to remove the multiple columns from DataFrame: if we want to remove the multiple columns from DataFrame using drop() function then we will mention column labels in List form under drop() function. Syntax to remove multiple columns from DataFrame: -

DataFrame_object . drop([label 1 , label 2 , ....., label n] , axis=1 , inplace=True)

Column label in List form.

Example 1 to remove the multiple column from DataFrame using drop() function:-

Remove the column `Unit Test 1' and `points1'.

OUTPUT: -

Column `UT1' and `points1' will be deleted from DataFrame.

Example 1 to remove the multiple column from DataFrame using drop() function:Remove the column `Name' and `points2' from given DataFrame.

Column `Name' and `points2' will be deleted from DataFrame.

OUTPUT: -

2. pop() function: - pop() function can also be used to remove or delete the column from DataFrame. Under pop() function we will mention column_label that we want to remove from DataFrame.

Syntax to use the pop() function to remove the column from

DataFrame: DataFrame_object . pop(column_label)

Name of column that we want to remove from DataFrame.

Example 1 to remove column from DataFrame using pop() function: Remove the column `points1' from DataFrame.

OUTPUT: -

Column `points1' will be deleted from DataFrame.

Example 2 to remove column from DataFrame using pop() function: Remove the column `points2' from DataFrame.

OUTPUT: -

Column `points2' will be deleted from DataFrame. Note: using pop() function we are only able to remove single column

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download