Reputation: 8996
For years I've used Pandas on a daily basis and often (but not nearly as frequently) use Numpy. Most of the time I'll do something like:
import pandas as pd
import numpy as np
But [EDIT: prior to pandas 2.0] there is also the option of using Numpy directly from Pandas:
df['value'] = pd.np.where(df['date'] > '2020-01-01', 1, 0)
Does anyone know if either one of these options is significantly more performant than the other?
Upvotes: 1
Views: 5056
Reputation: 9156
Both are importing the same library. There should not be any performance differences. It is just an alias for the same code. However, np.array
is preferable over pd.np.array
because it saves you three characters to type.
Upvotes: 2
Reputation: 120479
pandas.np
was removed in Pandas 2.0.0 and previously deprecated in Pandas 1.0.0:
<ipython-input-631-4160e33c868a>:1: FutureWarning: The pandas.np module is
deprecated and will be removed from pandas in a future version.
Import numpy directly instead
But for what it's worth, you can check that it was the same module in the source code.
Upvotes: 7