Reputation: 4732
This seems clunky:
col = df['col']
df.drop(columns=['col'], inplace=True)
Is there a way to drop a columns and return it on the same line?
Upvotes: 5
Views: 2830
Reputation: 82785
Looks like you need df.pop()
Ex:
df = pd.DataFrame(pd.np.random.randint(0, 10, (4,3)), columns=['a','b','c'])
a = df.pop("a")
Upvotes: 11