Andreas K.
Andreas K.

Reputation: 399

Pandas command don't work - why? (example: df.drop(...))

I am a little (more) clueless. It's not that the course I try to fulfill is a little bit above my capabilities or that my pandas knowledge is only rudimentary. But now on top even examples from the pandas.org site don't work neither in my Python Notebook nor in the Python notebook provided by Coursera.

here is an example taken from here: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop.html#pandas.DataFrame.drop

import pandas as pd
import numpy as np

df = pd.DataFrame(np.arange(12).reshape(3,4),
                      columns=['A', 'B', 'C', 'D'])
print(df)

df.drop(['B', 'C'], axis=1)    
print(df)

And these are my results in my local notebook as well the Coursera notebook

A B C D

0 0 1 2 3

1 4 5 6 7

2 8 9 10 11

A B C D

0 0 1 2 3

1 4 5 6 7

2 8 9 10 11

In short: nothing happened?!?

Any ideas? It is quite difficult for me to learn Python, Numpy, Pandas and so on in general as I start more or less from scratch. But if even the given examples don't work ...

Upvotes: 1

Views: 203

Answers (1)

jezrael
jezrael

Reputation: 862781

Need assign output back:

df = df.drop(['B', 'C'], axis=1)

Or use inplace=True:

df.drop(['B', 'C'], axis=1, inplace=True)

Upvotes: 1

Related Questions