简体   繁体   English

同时导入 Pandas 和 Numpy?

[英]Import both Pandas and Numpy?

For years I've used Pandas on a daily basis and often (but not nearly as frequently) use Numpy.多年来,我每天都在使用 Pandas,并且经常(但不那么频繁)使用 Numpy。 Most of the time I'll do something like:大多数时候我会做这样的事情:

import pandas as pd
import numpy as np

But there is also the option of using Numpy directly from Pandas:但也有直接从 Pandas 使用 Numpy 的选项:

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?有谁知道这些选项中的任何一个是否比另一个更高效?

Using pd.np is deprecated:不推荐使用pd.np

<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

You can check this is the same module:您可以检查这是同一个模块:

https://github.com/pandas-dev/pandas/blob/master/pandas/__init__.py#L205-L216 https://github.com/pandas-dev/pandas/blob/master/pandas/__init__.py#L205-L216

Both are importing the same library.两者都导入相同的库。 There should not be any performance differences.不应该有任何性能差异。 It is just an alias for the same code.它只是相同代码的别名。

Eg np.array is preferable over pd.np.array because it saves you three characters to type.例如np.array是在最好pd.np.array ,因为它可以节省您的三个字符类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM