Pandas: [Enhancement] Using del in the drop(where inplace=True) is faster than the current drop method

Created on 22 Jul 2018  路  3Comments  路  Source: pandas-dev/pandas

Code Sample, a copy-pastable example if possible

# Your code here
a = time()
df.drop('x',axis=1,inplace=True)
print(time()-a)#0.02...
#imagine we got the values of column x again...
a = time()
del df['x']
print(time()-a)#0.0009...

#the del method is faster to delete the column in place...

Problem description

I cant seem to locate the drop function anywhere or else I would commit it myself. What I am imagining is the drop would check if kwarg inplace is true, if it is, it would do something to drop the table, right?
If I am right, then cant we just replace the something with del dataframe[column_name]? I am not an expert programmer like y'all, so please do correct me if I am wrong...Thank you

Expected Output

Output of pd.show_versions()

0.23.0

All 3 comments

Guys How do I make this an enhancement instead of issue?

drop is the canonical way to delete columns from a DataFrame. There is a discussion on SO which while old still touches on relevant aspects:

https://stackoverflow.com/questions/13411544/delete-column-from-pandas-dataframe-using-del-df-column-name

I'm not entirely clear on what you are after as you touch on a few points here, but if you wanted to just have a general discussion on this you'd be better served on the Gitter or mailing list.

Ok, thank you, sorry for disturbing

Was this page helpful?
0 / 5 - 0 ratings