Search code examples
python-3.xpandasdataframedata-analysisdrop

How to drop a row of a pandas


Dataset

f = pd.DataFrame(np.arange(16).reshape(4, 4),columns=['A', 'B', 'C', 'D'])

I tried the below way, but the column is not getting removed. Please help me!

f.drop([3])
f.head()

I even tried iloc method, but no improvements were there. Please help me!


Solution

  • You need to assign it or adding inplace

    f = f.drop([3]) # f.drop([3],inplace=True)
    

    For column drop

    f = f.drop(f.columns[3],axis=1)
    Out[184]: 
        A   B   C
    0   0   1   2
    1   4   5   6
    2   8   9  10
    3  12  13  14