e2nIEE / pandapower

Convenient Power System Modelling and Analysis based on PYPOWER and pandas
https://www.pandapower.org
Other
847 stars 478 forks source link

None of [Int64Index([ ')] are in the [index]" #2237

Closed seilsepour closed 1 month ago

seilsepour commented 6 months ago

Hi there, I am new in pandapower. I have created an IEEE-33 bus network, and I want to plot it now. I wrote this code:

plot.fuse_geodata(net) bc = plot.create_bus_collection(net, net.bus.index, size=.2, color=colors[0], zorder=10) tlc, tpc = plot.create_trafo_collection(net, net.trafo.index, color="g") lcd = plot.create_line_collection(net, net.line.index, color="grey", linewidths=0.5, use_bus_geodata=True) sc = plot.create_bus_collection(net, net.ext_grid.bus.values, patch_type="rect", size=.5, color="y", zorder=11) plot.draw_collections([lcd, bc, tlc, tpc, sc], figsize=(8,6))

when I run it, I got the following error in the second line:

/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py in _raise_if_missing(self, key, indexer, axis_name) 6128 if not self._should_compare(target) and not self._should_partial_index(target): 6129 # _should_partial_index e.g. IntervalIndex with numeric scalars -> 6130 # that can be matched to Interval scalars. 6131 return self._get_indexer_non_comparable(target, method=None, unique=False) 6132

KeyError: "None of [Int64Index([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,\n 33],\n dtype='int64')] are in the [index]"

Would you please help me?

pawellytaev commented 1 month ago

Hi @seilsepour, I'm not sure why you use plot.fuse_geodata, I assume this creates the issue that you have no bus_geodata for your net.bus values. Here's some code that should make it work:

import pandapower as pp
import pandapower.networks as pn
import pandapower.plotting as plot
import seaborn as sns
import matplotlib.pyplot as plt

colors=sns.color_palette('colorblind')
net = pn.case33bw()

# plot.fuse_geodata(net)
bc = plot.create_bus_collection(net, net.bus.index, size=.2, color=colors[0], zorder=10)
# tlc, tpc = plot.create_trafo_collection(net, net.trafo.index, color="g")
lcd = plot.create_line_collection(net, net.line.index, color="grey", linewidths=0.5, use_bus_geodata=True)
sc = plot.create_bus_collection(net, net.ext_grid.bus.values, patch_type="rect", size=.5, color="y", zorder=11)
plot.draw_collections([lcd, bc, sc], figsize=(8,6))
plt.show()