Python Forum
Dropping a column from pandas dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dropping a column from pandas dataframe
#3
You should check the documentation of pandas.DataFrame.drop and version of pandas you are using (for example 'columns' is available from pandas 0.21)

It works for me with my dummy dataframe both with labels and with columns:

- df.drop(labels='(Vol., Price, Open, High, Low)', axis=1)
- df.drop(columns='(Vol., Price, Open, High, Low)')

If you want change the dataframe then you should set inplace:

- df.drop(columns='(Vol., Price, Open, High, Low)', inplace=True)

EDIT:

ninjad by ThomasL

I used this code to create dummy dataframe:

df = pd.DataFrame({'numbers': range(1, 4), 'letters': [*'abc'], '(Vol., Price, Open, High, Low)': 42})
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: Dropping a column from pandas dataframe - by perfringo - Sep-04-2019, 11:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Add NER output to pandas dataframe dg3000 0 243 Apr-22-2024, 08:14 PM
Last Post: dg3000
  concat 3 columns of dataframe to one column flash77 2 903 Oct-03-2023, 09:29 PM
Last Post: flash77
  HTML Decoder pandas dataframe column mbrown009 3 1,116 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  attempt to split values from within a dataframe column mbrown009 8 2,477 Apr-10-2023, 02:06 AM
Last Post: mbrown009
  Use pandas to obtain cartesian product between a dataframe of int and equations? haihal 0 1,161 Jan-06-2023, 10:53 PM
Last Post: haihal
  pandas column percentile nuncio 7 2,540 Aug-10-2022, 04:41 AM
Last Post: nuncio
  Pandas Dataframe Filtering based on rows mvdlm 0 1,488 Apr-02-2022, 06:39 PM
Last Post: mvdlm
  Pandas dataframe: calculate metrics by year mcva 1 2,376 Mar-02-2022, 08:22 AM
Last Post: mcva
  Pandas dataframe comparing anto5 0 1,302 Jan-30-2022, 10:21 AM
Last Post: anto5
  PANDAS: DataFrame | Replace and others questions moduki1 2 1,858 Jan-10-2022, 07:19 PM
Last Post: moduki1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020