Error crs when reading a shapefile with geopandas in jupyter - pandas

I´m trying to read a shapefile with geopandas
Quito_full =gpd.read_file('./shapefiles/administraciones_zonales.shp')
Simple as that but I keep getting the following error
CRSError: Invalid projection: epsg:32717: (Internal Proj Error: proj_create: SQLite error on SELECT name, coordinate_system_auth_name, coordinate_system_code, geodetic_crs_auth_name, geodetic_crs_code, conversion_auth_name, conversion_code, area_of_use_auth_name, area_of_use_code, text_definition, deprecated FROM projected_crs WHERE auth_name = ? AND code = ?: no such column: area_of_use_auth_name)
This are my versions
print(sys.version)
3.8.12 (default, Oct 12 2021, 03:01:40) [MSC v.1916 64 bit (AMD64)]
import pyproj
print(pyproj.__version__)
2.6.1.post1
import geopandas
print(geopandas.__version__)
0.9.0
Is there anyway to fix this error, I have been trying everything!.

have downloaded shape file from here https://hub.arcgis.com/datasets/esrimarketing::administraciones-zonales/explore?location=-0.167571%2C-78.559309%2C10.38
it is epsg:4326, but then projected to epsg:32717. No issues
your pyproj and geopandas versions are a bit outdated. Your error primarily points to an issue with pyproj
from pathlib import Path
import geopandas as gpd
gdf = gpd.read_file(list(Path.home().joinpath("Downloads").glob("**/Administraciones_Zonales.shp"))[0])
gdf.to_crs("epsg:32717").explore()
versions
import pyproj, sys
print(gpd.__version__, pyproj.__version__, sys.version)
0.10.2 3.3.0 3.9.10 (main, Jan 15 2022, 11:48:00)
[Clang 13.0.0 (clang-1300.0.29.3)]

Related

ModuleNotFoundError: No module named 'numpy.random.bit_generator' while importing sklearn

I installed opencv, tensorflow and other tools on my Macbook M1 air by watching this tutorial:
After installing, opencv and tensorflow works fine but when I try to import sklearn the mentioned error occurs. Here is the Error:
File ~/miniforge3/envs/ml/lib/python3.8/site-packages/scipy/stats/distributions.py:11, in <module>
8 from ._distn_infrastructure import (rv_discrete, rv_continuous, rv_frozen)
10 from . import _continuous_distns
---> 11 from . import _discrete_distns
13 from ._continuous_distns import *
14 from ._discrete_distns import *
File ~/miniforge3/envs/ml/lib/python3.8/site-packages/scipy/stats/_discrete_distns.py:21, in <module>
17 from ._distn_infrastructure import (
18 rv_discrete, _ncx2_pdf, _ncx2_cdf, get_distribution_names,
19 _check_shape)
20 import scipy.stats._boost as _boost
---> 21 from ._biasedurn import (_PyFishersNCHypergeometric,
22 _PyWalleniusNCHypergeometric,
23 _PyStochasticLib3)
25 class binom_gen(rv_discrete):
26 r"""A binomial discrete random variable.
27
28 %(before_notes)s
(...)
51
52 """
File _biasedurn.pyx:1, in init scipy.stats._biasedurn()
ModuleNotFoundError: No module named 'numpy.random.bit_generator'
The tutorial I was following suggested the exact version of numpy and python. I looked some places for help and they suggested updating the numpy. I'm not sure whether I should do that because that may break other libraries like OpenCV.
versions:
python 3.8.6
numpy 1.18.5
scikit-learn 1.1.1
scipy 1.8.1

plotting a graph in an xml file

I want to show the graph using the python code below, but I am getting a syntax error as seen on the image. Please help to correct this error. I am using Python 3
import os
import sys
import fnss
import networkx as nx
import fnss
import cvxopt
import numpy as np
import codecs
import random
import matplotlib.pyplot as plt
topo_str = 'topo_peter.xml'
topology = fnss.read_topology(topo_str)
topology_directed = topology.to_directed(topology)
print nx.info(topology_directed)
nx.draw(topology_directed)
plt.show()
and this is the am getting
File "<ipython-input-1-fa7157dd7268>", line 14
print nx.info(topology_directed)
^
SyntaxError: invalid syntax
Based on the information provided:
Python version: 3
Error message: invalid syntax on line 14 -> print nx.info(topology_directed)
It is clearly a simple syntax error for people using Python 3 to execute a Python 2 statement.
print "something" # is valid for Python 2, but not Python 3
For Python 3, use
print("something", "and more", "even more")
So changing print nx.info(topology_directed) to print(nx.info(topology_directed)) solves the problem.

Should we use pandas.compat.StringIO or Python 2/3 StringIO?

StringIO is the file-like string buffer object we use when reading pandas dataframe from text, e.g. "How to create a Pandas DataFrame from a string?"
Which of these two imports should we use for StringIO (within pandas)? This is a long-running question that has never been resolved over four years.
StringIO.StringIO (Python 2) / io.StringIO (Python 3)
Advantages: more stable for futureproofing code, but forces us to version-fork, e.g. see code at bottom from EmilH.
pandas.compat.StringIO
pandas.compat is a 2/3 compatibility package ("without the need for 2to3") introduced back in 0.13.0 (Jan 2014)
pandas.compat package is still marked 'private' as of 0.22 and no plans to make 'public' says "Warning The pandas.core, pandas.compat, and pandas.util top-level modules are considered to be PRIVATE. Stability of functionality in those modules in not guaranteed." although they essentially haven't broken since 0.13
pandas.compat source defines
the imports builtins, StringIO/cStringIO, BytesIO, cPickle, httplib, iterator versions of range, filter, map and zip, plus other necessary elements for Python 3 compatibility - see the 0.13.0 whatsnew
Version 2/3 forking code for imports from standard (from EmilH):
import sys
if sys.version_info[0] < 3:
from StringIO import StringIO
else:
from io import StringIO
# Note: but this is very much a poor-man's version of pandas.compat, which contains much much more
Note:
pandas.compat has existed since pandas 0.13.0 (Jan 2014) as a subpackage within pandas
it also seems to have been released as a standalone package: 0.1.0 (Jun 10, 2017) and 0.1.1 (Jun 10, 2017)
I know this is an old question, but I followed breadcrumbs here, so perhaps still worth answering. It's not totally definitive, but current Pandas documentation suggests using the built in StringIO rather than it's own internal methods.
For examples that use the StringIO class, make sure you import it with from io import StringIO for Python 3.
FYI, as of pandas 0.25, StringIO was removed from pandas.compat (PR #25954), so you'll now see:
from pandas.compat import StringIO
ImportError: cannot import name 'StringIO' from 'pandas.compat'
This means the only answer is to import from the io module.

Reticulate not working with numpy 1.13.3

I am using python 3.6 and numpy 1.13.3. On numpy import, I am getting an error Cannot import name 'dtype'
reticulate::import("numpy") throws
Error in py_run_string_impl(paste0("import sys; sys.path.append('", system.file("python", :
ImportError: cannot import name 'dtype'
Should I need to use some old version of numpy to fix this issue

Issue with inverting sparse matrix pylab

I try to do the following
from scipy import *
from numpy import *
import scipy as s
import numpy as np
import math
import scipy.sparse as l
from plot import Graph3DSolution
import numpy.linalg as lin
currentSol=s.sparse.linalg.inv(I-C)*A*lastSol
Im missing out some code but the issue is this
Traceback (most recent call last):
File "explict1wave.py", line 62, in <module>
currentSol=s.sparse.linalg.inv(I-C)*A*lastSol
AttributeError: 'module' object has no attribute 'linalg'
Python 2.7.6 |Anaconda 1.9.1 (x86_64)| (default, Jan 10 2014, 11:23:15)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
im>>> import scipy
>>> scipy.__version__
'0.14.0'
>>>
I look up the documentation and it seems these libraries existed since .12 . I dont know what the issue is, but im sure its something simple im not seeing.
>>> import scipy as s
>>> s.sparse
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'sparse'
>>>
>>> from scipy.sparse import linalg
>>> linalg.inv
<function inv at 0x19b1758>
>>>
General recommendations for importing functions from scipy .
On a side note, best avoid star imports. These from scipy import *, from numpy import * are not recommended and not needed here. Same for import scipy as s.