Python 10 分钟到 Pandas 教程 - to_numpy() 不存在?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54424818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
10 Minutes to Pandas tutorial - to_numpy() does not exist?
提问by Ankur B.
Following: https://pandas.pydata.org/pandas-docs/stable/getting_started/10min.htmlThis - df.to_numpy() throws an AttributeError: 'DataFrame' object has no attribute 'to_numpy'
以下:https://pandas.pydata.org/pandas-docs/stable/getting_started/10min.html 这 - df.to_numpy() 抛出一个 AttributeError: 'DataFrame' object has no attribute 'to_numpy'
Not sure why.
不知道为什么。
采纳答案by Owen L.
This feature was just added in Version 0.24.0, which was released a couple of days ago. If you haven't updated yet, the attribute doesn't exist! Once you update pandas the problem should resolve itself.
此功能刚刚在几天前发布的 0.24.0 版中添加。如果您还没有更新,则该属性不存在!更新熊猫后,问题应该会自行解决。
回答by markuscosinus
Try df.values
instead. This will have the same effect for versions of pandas prior to 0.24.0
试试吧df.values
。这对 0.24.0 之前的 pandas 版本具有相同的效果
回答by prosti
To check your version of pandas
检查您的熊猫版本
import pandas as pd
print(pd.__version__)
If it's not 0.24, you need to update pandas else you can use df.values
.
To upgrade pandas under Anaconda, grab Anaconda command prompt and type:
如果不是 0.24,则需要更新 pandas,否则可以使用df.values
. 要在 Anaconda 下升级 pandas,请获取 Anaconda 命令提示符并键入:
conda update pandas
To upgrade pandas under Python3
在 Python3 下升级 pandas
pip3 install --upgrade pandas
One really great thing with to_numpy()
method is the copy
parameter it provides:
方法的一个真正伟大的事情to_numpy()
是copy
它提供的参数:
npa=df.to_numpy() #editing npa will reflect in df
npa=to_numpy(copy=True) #editing npa will not affect the df
回答by Dhiren Biren
Need to update Pandas 0.24.0s to use df.values() and df.to_numpy()
需要更新 Pandas 0.24.0s 才能使用 df.values() 和 df.to_numpy()