我正在登录各种网络设备,并尝试查看输出。下面是我正在运行的脚本,它工作得非常好。当我试图确定po1、allin1、sta1、saa1、stn1的产量时,我面临着这个问题。我已经给出了下面所有变量的输出。po1将是这里的源,如果任何索引在其他变量中不可用,则需要显示“NAn”。如果你对理解这个问题有异议,请告诉我。
下面是我得到的错误。当我把轴设为1时,我得到了这个错误。
> ValueError Traceback (most recent call last)
<ipython-input-131-dce15d2880ec> in <module>()
----> 1 csv_data1 = pd.concat([po1.set_index('Interface'), allin1.set_index('Interface'), sta1.set_index('Interface'), saa1.set_index('Interface'), stn1.set_index('Interface')],1, sort=True).reset_index()
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\reshape\concat.py in concat(objs, axis, join, join_axes, ignore_index, keys, levels, names, verify_integrity, sort, copy)
224 verify_integrity=verify_integrity,
225 copy=copy, sort=sort)
--> 226 return op.get_result()
227
228
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\reshape\concat.py in get_result(self)
421 new_data = concatenate_block_managers(
422 mgrs_indexers, self.new_axes, concat_axis=self.axis,
--> 423 copy=self.copy)
424 if not self.copy:
425 new_data._consolidate_inplace()
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\internals.py in concatenate_block_managers(mgrs_indexers, axes, concat_axis, copy)
5423 blocks.append(b)
5424
-> 5425 return BlockManager(blocks, axes)
5426
5427
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\internals.py in __init__(self, blocks, axes, do_integrity_check)
3280
3281 if do_integrity_check:
-> 3282 self._verify_integrity()
3283
3284 self._consolidate_check()
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\internals.py in _verify_integrity(self)
3491 for block in self.blocks:
3492 if block._verify_integrity and block.shape[1:] != mgr_shape[1:]:
-> 3493 construction_error(tot_items, block.shape[1:], self.axes)
3494 if len(self.items) != tot_items:
3495 raise AssertionError('Number of manager items must equal union of '
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\internals.py in construction_error(tot_items, block_shape, axes, e)
4841 raise ValueError("Empty data passed with indices specified.")
4842 raise ValueError("Shape of passed values is {0}, indices imply {1}".format(
-> 4843 passed, implied))
4844
4845
ValueError: Shape of passed values is (4, 9), indices imply (4, 5)
ValueError: Shape of passed values is (4, 9), indices imply (4, 5)
switch = ['chi41vg224r3', 'chi41vg224r2', 'chi41s12', 'chi41s5', 'chi41s4', 'chi41s7', 'chi41s6', 'chi41s3', 'chi41m1', 'chi41m1', 'chi41m1', 'chidc41m4', 'chidc41m4', 'chidc41m4', 'chidc41m4']
port = ['Fas 0/0', 'Fas 0/0', 'Gig 1/1/2', 'Ten 6/1', 'Ten 6/1', 'Ten 6/1', 'Ten 6/1', 'Ten 6/1', 'Gig 3/2', 'Gig 5/2', 'Gig 5/1', 'Eth 1/34', 'Eth 1/33', 'Eth 1/32', 'Eth 1/31']
po1 = pd.DataFrame([])
stn1 = pd.DataFrame([])
sta1 = pd.DataFrame([])
saa1 = pd.DataFrame([])
allin1 = pd.DataFrame([])
for (sw, op) in zip(switch, other_port):
switch1 = {'device_type': 'cisco_ios', 'ip': sw, 'username': user, 'password': password, 'port':'22'}
connect1= ConnectHandler(**switch1)
opout =connect1.send_command_expect('show run interface '+op)
connect1.disconnect()
cfg1 = opout.split('\n')
parse1 = CiscoConfParse(cfg1)
intera = parse1.find_objects(r"^interface")
interf = []
for interfa in intera:
tx = interfa.text
interf.append(tx)
df2 = pd.DataFrame(dict(Interface=interf))
po1 = po1.append(df2)
ALL1 = parse1.find_children_w_parents(r"^interface", r"^")
STA1 = parse1.find_children_w_parents(r"^interface", r"switchport trunk allowed ")
SAA1 = parse1.find_children_w_parents(r"^interface", r"switchport trunk allowed add ")
STN1 = parse1.find_children_w_parents(r"^interface", r"switchport trunk native ")
ALL_T1 = pd.DataFrame(list(zip(*(interf, ALL1))), columns=('Interface', 'ALL1'))
allin1 = allin1.append(ALL_T1)
STA_T1 = pd.DataFrame(list(zip(*(interf, STA1))), columns=('Interface', 'STA1'))
sta1 = sta1.append(STA_T1)
SAA_T1 = pd.DataFrame(list(zip(*(interf, SAA1))), columns=('Interface', 'SAA1'))
saa1 = saa1.append(SAA_T1)
STN_T1 = pd.DataFrame(list(zip(*(interf, STN1))), columns=('Interface', 'STN1'))
stn1 = stn1.append(STN_T1)
csv_data = pd.concat([po1.set_index('Interface'), allin1.set_index('Interface'), sta1.set_index('Interface'), saa1.set_index('Interface'), stn1.set_index('Interface')],1, sort=True).reset_index()
csv_data.rename(columns={'index': 'NeighborINT'}, inplace=True)
po1的产量:
Interface
0 interface GigabitEthernet1/1/2
0 interface TenGigabitEthernet6/1
0 interface TenGigabitEthernet6/1
0 interface TenGigabitEthernet6/1
0 interface TenGigabitEthernet6/1
0 interface TenGigabitEthernet6/1
0 interface GigabitEthernet3/2
0 interface GigabitEthernet5/2
0 interface GigabitEthernet5/1
allin1的输出:
Interface ALL1
0 interface GigabitEthernet1/1/2 description uplink to chi41m2
0 interface TenGigabitEthernet6/1 description Uplink
0 interface TenGigabitEthernet6/1 description Uplink
0 interface TenGigabitEthernet6/1 description Uplink
0 interface TenGigabitEthernet6/1 description Uplink
0 interface TenGigabitEthernet6/1 description Uplink
0 interface GigabitEthernet3/2 description CHI41LABFW1-Eth1
0 interface GigabitEthernet5/2 description trunk to chi41m2
0 interface GigabitEthernet5/1 description trunk to chi41m2
sta的输出:
Interface STA1
0 interface GigabitEthernet1/1/2 switchport trunk allowed vlan 20,41,99-101,10...
0 interface TenGigabitEthernet6/1 switchport trunk allowed vlan 20,41,45,102,10...
0 interface TenGigabitEthernet6/1 switchport trunk allowed vlan 20,41,45,102,10...
0 interface TenGigabitEthernet6/1 switchport trunk allowed vlan 20,41,106,107,1...
0 interface TenGigabitEthernet6/1 switchport trunk allowed vlan 20,41,99-101,10...
0 interface TenGigabitEthernet6/1 switchport trunk allowed vlan 20,41,100,101,1...
saa1的输出(此处为空,因为在上述脚本中没有匹配项):
Interface SAA1
stn1的输出:
Interface STN1
0 interface GigabitEthernet1/1/2 switchport trunk native vlan 41
0 interface TenGigabitEthernet6/1 switchport trunk native vlan 41
0 interface TenGigabitEthernet6/1 switchport trunk native vlan 41
0 interface TenGigabitEthernet6/1 switchport trunk native vlan 41
0 interface TenGigabitEthernet6/1 switchport trunk native vlan 41
0 interface TenGigabitEthernet6/1 switchport trunk native vlan 41
我得到的输出后添加drop重复
和使用合并
而不是conat
。
po1_n = po1.drop_duplicates()
allin1_n = allin1.drop_duplicates()
sta1_n = sta1.drop_duplicates()
saa1_n = saa1.drop_duplicates()
stn1_n = stn1.drop_duplicates()
csv_data1 = po1_n.merge(allin1_n, on='Interface', how='outer').merge(sta1_n, on='Interface', how='outer').merge(saa1_n, on='Interface', how='outer').merge(stn1_n, on='Interface', how='outer')
我有两个数据帧,有84行,显然是相同的长度,但是当我想将它们合并到1 df(按列合并-将名称、边和偏移量合并到纬度和经度的右侧)时,我得到了这个错误,。 发生了什么事? 这是我的代码行
concat线给出 raise VALUERROR(f“传递值的形状为{传递},索引暗示{隐含}”)VALUERROR:传递值的形状为(18585,6),索引暗示(12390,6) 我不明白为什么上面写着18585。还有其他连接方法吗?请帮忙。 编辑:我想我找到了问题所在。 打印结果给了我以下信息 印刷原理图 结果Df最初是通过附加两个Df获得的 行号不是从0到12390的延续,而是从0到6194
我正在尝试合并一个(熊猫14.1)数据帧和一个系列。序列应该形成一个新列,带有一些NAs(因为序列的索引值是数据帧索引值的子集)。 这适用于玩具示例,但不适用于我的数据(详见下文)。 例子: 数据的情况(见下文)似乎基本相同——将一个系列与一个DatetimeIndex连接起来,该索引的值是数据帧的子集。但是它在标题中给出了ValueError(等等1 = (5, 286)等等2 = (5, 27
我以前在python中使用pyodbc,但现在我已经在一台新机器上安装了它(win 8 64位、python 2.7 64位、PythonXY和Spyder)。 我不知道为什么行为会改变。也许是我的Pandas版本,或者是pyodbc,但是更新是有问题的。我试图更新一些模块,但它搞砸了一切,我使用的任何方法(二进制文件--用于正确的机器/安装--PIP安装、easy-install,任何东西!等等
预测类的输出 y_的输出为真 我想得到这个代码的索引,并得到这个值错误。 错误痕迹 请告诉我哪里出了问题。
本文向大家介绍JS是按值传递还是按引用传递,包括了JS是按值传递还是按引用传递的使用技巧和注意事项,需要的朋友参考一下 按值传递 VS. 按引用传递 按值传递(call by value)是最常用的求值策略:函数的形参是被调用时所传实参的副本。修改形参的值并不会影响实参。 按引用传递(call by reference)时,函数的形参接收实参的隐式引用,而不再是副本。这意味着函数形参的值如果被