Delete column from pandas DataFrame

后端 未结 17 1392
一生所求
一生所求 2020-11-22 02:44

When deleting a column in a DataFrame I use:

del df[\'column_name\']

And this works great. Why can\'t I use the following?

         


        
17条回答
  •  悲&欢浪女
    2020-11-22 03:27

    Deleting a column using iloc function of dataframe and slicing, when we have a typical column name with unwanted values.

    df = df.iloc[:,1:] # removing an unnamed index column
    

    Here 0 is the default row and 1 is 1st column so ,1 where starts and stepping is taking default values, hence :,1: is our parameter for deleting the first column.

提交回复
热议问题