Is there a more conventional or readable way of achieving the same result?
The below code works, but it feels clunky.
df[df.columns[~df.columns.isin(['name'])]]
Use DataFrame.loc
, here :
means select all rows:
df.loc[:, ~df.columns.isin(['name'])]
Another idea is use DataFrame.drop
with errors='ignore'
for avoid errors if not exist name
column (same working like solution above):
df.drop('name', axis=1, errors='ignore')
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments