Del/drop - column.axis in data frames_Python(jupyter notebook)

Kindly tell me how to use drop/del a column/row in python (Jupyter Notebook) data frames.
I have tried -
df = df.drop(‘column_name’, axis = 1)
df = df.drop([column_index], axis = 1)
del df(‘column_name’)
All of them are not working.
!!Thanks a lot in advance!!!

Hi Dwaipayan,
This isn’t a general Jupyter notebook or Python thing. It looks like you are using the Pandas module, perhaps? Including that, or whatever module you are using, in your internet search for help will lead to more thorough results.

The documentation for Pandas drop method is here.
Building on the starting example there:

import numpy as np
df = pd.DataFrame(np.arange(12).reshape(3, 4), columns=['A', 'B', 'C', 'D'])
new_df = df.drop(['B'], axis=1)


   A   C   D
0  0   2   3
1  4   6   7
2  8  10  11

(I’ll keep making derived dataframes so I can use the one example as the start; however, obviously you could assign the new one to df.)
Or, for the row:

another_df =  df.drop([1], axis=0)


   A  B   C   D
0  0  1   2   3
2  8  9  10  11

There are other ways to subset the data, such as slicing:

sliced_df = df[['A', 'C', 'D']]


   A   C   D
0  0   2   3
1  4   6   7
2  8  10  11
1 Like

Hi fomightez,
Yes i am using Pandas module to read a csv file in DataFrame structure. I was using
my_file = pd.read_csv(‘target file location’, sep = ‘,’)
For me slicing is working to work with my selected columns.
Thanks a lot!!