Informatics Practices
Write statement(s) to delete a column from a DataFrame.
Python Pandas
2 Likes
Answer
The statements to delete a column from a DataFrame is:
del <Df object>[<column name>]
OR
df.drop([<column name>], axis = 1)
.
For example, the statement to delete a column Population
from a dataframe df
is del df['Population]
or df.drop('Population', axis = 1)
.
Answered By
1 Like
Related Questions
Write code statements for a dataframe df for the following :
(a) delete an existing column from it.
(b) delete rows from 3 to 6 from it.
(c) Check if the dataframe has any missing values.
(d) fill all missing values with 999 in it.
Write statement(s) to delete a row from a DataFrame.
Write statement(s) to change the value at 5th row, 6th column in a DataFrame df.
Write statement(s) to change the values to 750 at 4th row to 9th row, 7th column in a DataFrame df.