I come across a strange error when using range(a, b)
in Python, which says I made a TypeError
for calling GeoDataFrame
, while there should not be any GeoDataFrame
involved.
The process should not be related to GeoDataFrame
. For example, I tried to print the range(0,2)
, while getting the TypeError. No error would happen if using the list
directly (e.g.[1,2,3]
)
(The following are my codes for reference. They are generally for generating a network in Python-igraph from shapefiles.)
# Import packages
import pandas as pd
import geopandas as gpd
import numpy as np
import igraph as ig
# Import data
data = gpd.read_file(r"\streets.shp")
print(data)
data2 = gpd.read_file(r"\intersections.shp")
range = gpd.read_file(r"\streets_range.shp")
OD_matrix = gpd.read_file(r"\OD_data.gpkg", driver="GPKG")
# Make sure the intersection IDs are integers
data["Inter_ID0"] = data["Inter_ID0"].astype(int)
data["Inter_ID1"] = data["Inter_ID1"].astype(int)
# Create graph
G = ig.Graph()
G.add_vertices(data2.shape[0])
G.add_edges(list(zip(data["Inter_ID0"], data["Inter_ID1"])))
G.es['Length'] = data["Length"]
# Calculate shortest paths
for v in range(0, 7506):
path1 = G.get_shortest_paths(v, to=None, weights="Length", mode='all', output='epath')
path2 = G.get_shortest_paths(v, to=None, weights="Length", mode='all', output='vpath')
......
Results:
TypeError Traceback (most recent call last)
Cell In[4], line 2
1 matrix = pd.DataFrame([])
----> 2 for v in range(0, 7506):
3 path1 = G.get_shortest_paths(v, to=None, weights="Length", mode='all', output='epath')
4 path2 = G.get_shortest_paths(v, to=None, weights="Length", mode='all', output='vpath')
TypeError: 'GeoDataFrame' object is not callable
(So the traceback also did not refer to any line where GeoDataFrame is involved.)
You're assigning a variable to the keyword range
earlier in your code. Change the name of that variable.
streets_range = gpd.read_file(r"\streets_range.shp")