Does anyone know the fix for this "pd is not defined"? it seems to be combined with a dying kernel. I'm using Jupyter Notebook.
I had started with these imports and didn't get an error message so I was assuming that pandas was imported successfully
import pandas as pd
import numpy as np
Tried updating my Python version to 3.11
This should not be a python problem. Since import pandas as pd did not fail, you should try print out print(pd) and see where pandas is installed and maybe verify it is is properly installed. It should print out something like lib/python3.x/site-packages/pandas/__init__.py'.
I am trying to run a python program on a raspberry pi. The program uses the pandas library including the 'json_normalize' function. I have tried importing pandas with import pandas, and from pandas.io.json import json_normalize but I still get the error. I am using pandas version 0.23.3. Is it just a version problem or is there something else?
There is a problem with Pandas 0.23.
but, You still can run it with pandas 0.22
check this issue open for this problem
Given Python project, we can know the libraries it uses by checking the "import" part. But how can we know the version of a given library? For instance, the program has import pandas pd, how can we know the version of Pandas it uses?
import pandas as pd
print(pd.__version__)
I am currently , successfully, importing stock information from Yahoo using pandas-datareader. However, before the extracted data, I always get the following message:
FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
Would anyone have an idea of what it means and how to fix it?
Cause: The cause of this warning is that, basically, the pandas_datareader is importing a module from the pandas library that will be deprecated. Specifically, it is importing pandas.util.testing whereas the new preferred module will be pandas.testing.
Solution: First off this is a warning, and not an outright error, so it won't necessarily break your program. So depending on your exact use case, you may be able to ignore it for now.
That being said, there are a few options you can consider:
Option 1: Change the code yourself -- Go into the pandas_datareader module and modify the line of code in compat_init.py that currently says from pandas.util.testing import assert_frame_equal simply to from pandas.testing import assert_frame_equal. This will import the same function from the correct module.
Option 2: Wait for pandas-datareader to update --You can also wait for the library to be upgraded to import correctly and then run pip3 install --upgrade pandas-datareader. You can go to the Github repo for pandas-datareader and raise an issue.
Option 3: Ignore it -- Just ignore the warning for now since it doesn't break your program.
You may find the 'util.testing' code in pandas_datareader, which is separate from pandas.
If you are using this from pandas_datareader import data import it has deprecated.
Replace it with:
from pandas_datareader import data, wb
or
import pandas_datareader as pdr
Because many functions from the data module have been included in the top level API.
in your virtual environment, simply change the import statement in
/env/lib/site-packages/pandas_datareader/compat/__init__.py
(or the site-packages directory for python if you are not using a virtual environment)
from
from pandas.util.testing import assert_frame_equal
to
from pandas.testing import assert_frame_equal
Try below line to import, it will work.
import pandas_datareader.data as web
For more information find the below link.
https://www.reddit.com/r/learnpython/comments/fel32c/getting_a_future_warning_error_on_a_simple_web/
For mac OS open /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas_datareader/compat/__init__.py
change: from pandas.util.testing import assert_frame_equal
to: from pandas.testing import assert_frame_equal
I am trying to create a dataFrame in python and the only way I have found so far is to use the pandas library.
import pandas as pd
newfilename = pd.read_csv("filename.csv")
However, when I try to excute this code, I am getting an error which says:
ImportError: cannot import name Counter
I googled and found that in python 2.6 and older versions, this error is common and they said I should install backport_collections : 0.1 to solve this issue like is explained in the below page:
https://pypi.python.org/pypi/backport_collections/0.1
However, I have no experience in doing it in the unix virtual machine.
It seems that I have to download the package "backport_collections-0.1.tar.gz" and after that I dont know how to install it or in which directory to install it.
After installation I need to import counter as follows:
from backport_collections import Counter
Please advise me on how to install this package "backport_collections-0.1.tar.gz" as I am completely new to python.