1

I'm using pandas to manage some data frames.

In every tutorial I've seen so far, they import both numpy and pandas when working with pandas so I imported both.

I also recently installed flake8 linter, and its giving me the following message:

numpy as np imported but not used

Do both packages need to run together or can I delete that Numpy?

Portfedh
  • 178
  • 1
  • 13
  • You can use pandas as a standalone module. – DSteman Jul 21 '21 at 19:54
  • If you aren't explicitly using `numpy` functions you don't need to import it (by name). `pandas` will use it as needed, and methods like `df.to_numpy()` will give you a numpy array. Most commonly, though, I see people asking about using `np.where` to speed up calculations of new columns. – hpaulj Jul 21 '21 at 20:02

3 Answers3

5

No, you do not need to import numpy for pandas to function properly. Most tutorials use numpy for some computations which is why it is imported. Otherwise, pandas is self sufficient.

2

The answer is NO, numpy and pandas are not strictly bound. Sometimes you need the help of numpy to do some special works, like computations, that's why you may need to import and use.

But to work with pandas, numpy is not mandatory.

devReddit
  • 2,696
  • 1
  • 5
  • 20
  • 2
    Actually numpy is a pandas dependency and pandas called it internally. But if you are not using numpy explicitely you don't need to import it. – rpanai Jul 21 '21 at 19:56
2

You don't have to import numpy. Numpy and pandas are two different packages. They are both powerful libraries to edit data efficiently, and they are working together pretty good. This is why people use them together. But this does not mean you have to import both.

Still, do not remove numpy, since pandas depends numpy for some internal operations.

tolgayan
  • 108
  • 9