10 Minutes to Pandas tutorial – to_numpy() does not exist?
Question:
Following: https://pandas.pydata.org/pandas-docs/stable/getting_started/10min.html
This – df.to_numpy() throws an AttributeError: ‘DataFrame’ object has no attribute ‘to_numpy’
Not sure why.
Answers:
Try df.values
instead. This will have the same effect for versions of pandas prior to 0.24.0
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.
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:
conda update pandas
To upgrade pandas under Python3
pip3 install --upgrade pandas
One really great thing with to_numpy()
method is the copy
parameter it provides:
npa=df.to_numpy() #editing npa will reflect in df
npa=to_numpy(copy=True) #editing npa will not affect the df
Need to update Pandas 0.24.0s to use df.values() and df.to_numpy()
Following: https://pandas.pydata.org/pandas-docs/stable/getting_started/10min.html
This – df.to_numpy() throws an AttributeError: ‘DataFrame’ object has no attribute ‘to_numpy’
Not sure why.
Try df.values
instead. This will have the same effect for versions of pandas prior to 0.24.0
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.
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:
conda update pandas
To upgrade pandas under Python3
pip3 install --upgrade pandas
One really great thing with to_numpy()
method is the copy
parameter it provides:
npa=df.to_numpy() #editing npa will reflect in df
npa=to_numpy(copy=True) #editing npa will not affect the df
Need to update Pandas 0.24.0s to use df.values() and df.to_numpy()