pandas importing error while import pandas in python - python

When I import pandas library in python 3 it gave me a error.
Traceback (most recent call last):
File "C:\Users\KESHAV SHARMA\Desktop\VS Code\Compiler\as.py", line 1, in
import pandas as pd
File "C:\Users\KESHAV SHARMA\AppData\Roaming\Python\Python38\site-packages\pandas__init__.py", line 124, in
from pandas.core.computation.api import eval
File "C:\Users\KESHAV SHARMA\AppData\Roaming\Python\Python38\site-packages\pandas\core\computation\api.py", line 3, in
from pandas.core.computation.eval import eval
File "C:\Users\KESHAV SHARMA\AppData\Roaming\Python\Python38\site-packages\pandas\core\computation\eval.py", line 15, in
from pandas.core.computation.expr import Expr, _parsers
File "C:\Users\KESHAV SHARMA\AppData\Roaming\Python\Python38\site-packages\pandas\core\computation\expr.py", line 158, in
_all_nodes = frozenset(
File "C:\Users\KESHAV SHARMA\AppData\Roaming\Python\Python38\site-packages\pandas\core\computation\expr.py", line 160, in
lambda x: isinstance(x, type) and issubclass(x, ast.AST),
AttributeError: module 'ast' has no attribute 'AST'
Please help me to sort out this problem.

Try using only ast instead of ast.AST
lambda x: isinstance(x, type) and issubclass(x, ast)

Related

'NoneType' object has no attribute 'eglGetCurrentContext'

I am having a problem with python and pyopengl
I am just importing the modules, and getting errors, I checked and pip did install opengl and everything.
Here is my code
# ulWindow
import ulMath as ulm
import OpenGL.GL as gl
import OpenGL.GlE as gle
import glfw
def init() ->int|str:
if (not glfw.init()):
return "GLFW Failed to initialize"
return 0
And the error im getting:
Traceback (most recent call last):
File "src/ulWindow.py", line 3, in <module>
import OpenGL.GL as gl
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/GL/__init__.py", line 4, in <module>
from OpenGL.GL.VERSION.GL_1_1 import *
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/GL/VERSION/GL_1_1.py", line 14, in <module>
from OpenGL.raw.GL.VERSION.GL_1_1 import *
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/raw/GL/VERSION/GL_1_1.py", line 7, in <module>
from OpenGL.raw.GL import _errors
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/raw/GL/_errors.py", line 4, in <module>
_error_checker = _ErrorChecker( _p, _p.GL.glGetError )
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/error.py", line 183, in __init__
self._isValid = platform.CurrentContextIsValid
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
value = self.fget( obj )
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 356, in CurrentContextIsValid
return self.GetCurrentContext
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
value = self.fget( obj )
File "/home/jack3/.local/lib/python3.8/site-packages/OpenGL/platform/egl.py", line 106, in GetCurrentContext
return self.EGL.eglGetCurrentContext
AttributeError: 'NoneType' object has no attribute 'eglGetCurrentContext'
I have absolutely no clue what is going on, can someone help me out?

pandas: write empty DataFrame to HDF file

Is there a way to force pandas to write an empty DataFrame to an HDF file?
import pandas as pd
df = pd.DataFrame(columns=['x','y'])
df.to_hdf('temp.h5', 'xxx')
df2 = pd.read_hdf('temp.h5', 'xxx')
Output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../Python-3.6.3/lib/python3.6/site-packages/pandas/io/pytables.py", line 389, in read_hdf
return store.select(key, auto_close=auto_close, **kwargs)
File ".../Python-3.6.3/lib/python3.6/site-packages/pandas/io/pytables.py", line 740, in select
return it.get_result()
File ".../Python-3.6.3/lib/python3.6/site-packages/pandas/io/pytables.py", line 1518, in get_result
results = self.func(self.start, self.stop, where)
File ".../Python-3.6.3/lib/python3.6/site-packages/pandas/io/pytables.py", line 733, in func
columns=columns)
File ".../Python-3.6.3/lib/python3.6/site-packages/pandas/io/pytables.py", line 2986, in read
idx=i), start=_start, stop=_stop)
File ".../Python-3.6.3/lib/python3.6/site-packages/pandas/io/pytables.py", line 2575, in read_index
_, index = self.read_index_node(getattr(self.group, key), **kwargs)
File ".../Python-3.6.3/lib/python3.6/site-packages/pandas/io/pytables.py", line 2676, in read_index_node
data = node[start:stop]
File ".../Python-3.6.3/lib/python3.6/site-packages/tables/vlarray.py", line 675, in __getitem__
return self.read(start, stop, step)
File ".../Python-3.6.3/lib/python3.6/site-packages/tables/vlarray.py", line 811, in read
listarr = self._read_array(start, stop, step)
File "tables/hdf5extension.pyx", line 2106, in tables.hdf5extension.VLArray._read_array (tables/hdf5extension.c:24649)
ValueError: cannot set WRITEABLE flag to True of this array
Writing with format='table':
import pandas as pd
df = pd.DataFrame(columns=['x','y'])
df.to_hdf('temp.h5', 'xxx', format='table')
df2 = pd.read_hdf('temp.h5', 'xxx')
Output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../Python-3.6.3/lib/python3.6/site-packages/pandas/io/pytables.py", line 389, in read_hdf
return store.select(key, auto_close=auto_close, **kwargs)
File ".../Python-3.6.3/lib/python3.6/site-packages/pandas/io/pytables.py", line 722, in select
raise KeyError('No object named {key} in the file'.format(key=key))
KeyError: 'No object named xxx in the file'
Pandas version: 0.24.2
Thank you for your help!
Putting empty DataFrame into HDFStore in fixed format should work (maybe you need to check versions of other packages, e.g. tables):
# Versions
pd.__version__
tables.__version__
# DF
df = pd.DataFrame(columns=['x','y'])
df
# Dump in fixed format
with pd.HDFStore('temp.h5') as store:
store.put('df', df, format='f')
print('Read:')
store.select('df')
>>> '0.24.2'
>>> '3.5.1'
>>> x y
>>>
>>> Read:
>>> x y
Pytable really forbids to do so (at least it was), but for fixed pandas has its workaround.
But as discussed in same github issue there are made some efforts to fix this behavior for table as well. But looks like solution is still 'hangs in the air' because it was so at the end of march.

Import errors in Numba

The code :::: Does anyone can help me with this ?
from numba import vectorize
#vectorize(['int64(int64, int64)'], target='cuda')
def add_ufunc(x, y):
return x + y
print('a+b:\n', add_ufunc(a, b))
print()
print('b_col + c:\n', add_ufunc(b_col, c))
The error ::::
Traceback (most recent call last): File "array.py", line 1, in
from numba import vectorize File "/usr/lib/python3.7/site-packages/numba/init.py", line 11, in
from . import config, errors, _runtests as runtests, types File "/usr/lib/python3.7/site-packages/numba/config.py", line 9, in
import multiprocessing File "/usr/lib/python3.7/multiprocessing/init.py", line 16, in
from . import context File "/usr/lib/python3.7/multiprocessing/context.py", line 6, in
from . import reduction File "/usr/lib/python3.7/multiprocessing/reduction.py", line 136, in
import array File "/home/felipe/cuda/array.py", line 1, in
from numba import vectorize ImportError: cannot import name 'vectorize' from 'numba'
(/usr/lib/python3.7/site-packages/numba/init.py)

Python import pandas error [duplicate]

This question already has answers here:
IPython Notebook locale error [duplicate]
(4 answers)
Closed 6 years ago.
I'm using Python, and just start importing pandas, then the terminal reports failure like this:
import pandas as pd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/pandas/__init__.py", line 44, in <module>
from pandas.core.api import *
File "/usr/local/lib/python2.7/site-packages/pandas/core/api.py", line 9, in <module>
from pandas.core.groupby import Grouper
File "/usr/local/lib/python2.7/site-packages/pandas/core/groupby.py", line 17, in <module>
from pandas.core.frame import DataFrame
File "/usr/local/lib/python2.7/site-packages/pandas/core/frame.py", line 41, in <module>
from pandas.core.series import Series
File "/usr/local/lib/python2.7/site-packages/pandas/core/series.py", line 2909, in <module>
import pandas.tools.plotting as _gfx
File "/usr/local/lib/python2.7/site-packages/pandas/tools/plotting.py", line 28, in <module>
import pandas.tseries.converter as conv
File "/usr/local/lib/python2.7/site-packages/pandas/tseries/converter.py", line 7, in <module>
import matplotlib.units as units
File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1131, in <module>
rcParams = rc_params()
File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 975, in rc_params
return rc_params_from_file(fname, fail_on_error)
File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1100, in rc_params_from_file
config_from_file = _rc_params_in_file(fname, fail_on_error)
File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1018, in _rc_params_in_file
with _open_file_or_url(fname) as fd:
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1000, in _open_file_or_url
encoding = locale.getdefaultlocale()[1]
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 543, in getdefaultlocale
return _parse_localename(localename)
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 475, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8
What's wrong and what should I do, please?
You have your locale environment set to UTF-8. You most likely want something like en.UTF-8. This is not a problem with Pandas, or Matplotlib, for that matter, but with the locale module's handling of your incorrect environment:
>>> import locale
>>> locale._parse_localename('UTF-8')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-9c83313227dd> in <module>()
----> 1 locale._parse_localename('UTF-8')
/home/psilva/.virtualenvs/spark/lib/python2.7/locale.pyc in _parse_localename(localename)
473 elif code == 'C':
474 return None, None
--> 475 raise ValueError, 'unknown locale: %s' % localename
476
477 def _build_localename(localetuple):
ValueError: unknown locale: UTF-8
>>> locale._parse_localename('en.UTF-8')
('en_US', 'UTF-8')
Setting one of LC_ALL, LC_CTYPE, LANG, or LANGUAGE to
something sensible like 'en_US.UTF-8' or 'C' should fix the problem.

Fixed_quad Error With Functions

Keeping it simple:
----------------------------------
from mpmath import *
from scipy.integrate import *
mp.dps=30
def F(x):
return Q**(x)
Q=735
print fixed_quad(F,0,1,n=1)[0]
print fixed_quad(F,0,1,n=2)[0]
print fixed_quad(F,0,1,n=3)[0]
--------------------
returns
27.1108834235
93.1213589089
109.673420158
However, if I change F(x) from “Q**(x)” to even just a simple function—e.g., “cos(x)”—I get
--------------------
Traceback (most recent call last):
File "Test.py", line 7, in <module>
print fixed_quad(F,0,1,n=1)[0]
File "/usr/lib/python2.7/dist-packages/scipy/integrate/quadrature.py", line 67, in fixed_quad
return (b-a)/2.0*sum(w*func(y,*args),0), None
File "Test.py", line 5, in F
return cos(x)
File "/usr/lib/pymodules/python2.7/mpmath/ctx_mp_python.py", line 984, in f
x = ctx.convert(x)
File "/usr/lib/pymodules/python2.7/mpmath/ctx_mp_python.py", line 662, in convert
return ctx._convert_fallback(x, strings)
File "/usr/lib/pymodules/python2.7/mpmath/ctx_mp.py", line 614, in _convert_fallback
raise TypeError("cannot create mpf from " + repr(x))
TypeError: cannot create mpf from array([ 0.5])
Is this some known bug? Or is “fixed_quad” only meant for certain uses, not general integration (like “trapz”)?
All of the other regulars (“quad”, “dblquad”, “tplquad”, “nquad”) donʼt seem to have that problem/error.

Categories

Resources