group1 = nr.filter(F(groups__contains="huawei_group10"))
时间: 2023-06-13 22:06:32 浏览: 52
这行代码是使用Pyspark中的DataFrame API对名为`nr`的DataFrame进行过滤操作,筛选出`groups`字段包含字符串`"huawei_group10"`的行,将结果保存到`group1`变量中。
具体来说,`F(groups__contains="huawei_group10")`是一个过滤条件,表示`groups`字段包含字符串`"huawei_group10"`,`nr.filter()`方法将这个过滤条件应用到`nr` DataFrame中,返回一个新的DataFrame,其中包含符合条件的行。
相关问题
#!/usr/bin/env python #coding: utf-8 import os from time import time from datetime import datetime from netmiko import ConnectHandler from openpyxl import Workbook from openpyxl import load_workbook def read_device_excel( ): ip_list = [] wb1 = load_workbook('E:\/Users/Wayne_Peng/Desktop/cs_lab.xlsx') ws1 = wb1.get_sheet_by_name("Sheet1") for cow_num in range(2,ws1.max_row+1): ipaddr = ws1["a"+str(cow_num)].value ip_list.append(ipaddr) return ip_list def get_config(ipaddr): session = ConnectHandler(device_type="huawei", ip=ipaddr, username="mtlops", password="cisco,123", banner_timeout=300) print("connecting to "+ ipaddr) print ("---- Getting HUAWEI configuration from {}-----------".format(ipaddr)) # config_data = session.send_command('screen-length 0 temporary') # config_data = session.send_command('dis cu | no-more ') # command = 'display version | display cpu-usage | display memory-usage' # config_data = session.send_command(command) commands = ['display version', 'display cpu-usage', 'display memory-usage'] config_data = '' for cmd in commands: output = session.send_command_timing(cmd) config_data += f'{cmd}\n{output}\n' session.disconnect() return config_data def write_config_to_file(config_data,ipaddr): now = datetime.now() date= "%s-%s-%s"%(now.year,now.month,now.day) time_now = "%s-%s"%(now.hour,now.minute) #---- Write out configuration information to file config_path = 'E:\/Users/Wayne_Peng/Desktop/' +date verify_path = os.path.exists(config_path) if not verify_path: os.makedirs(config_path) config_filename = config_path+"/"+'config_' + ipaddr +"_"+date+"_" + time_now # Important - create unique configuration file name print ('---- Writing configuration: ', config_filename) with open( config_filename, "w",encoding='utf-8' ) as config_out: config_out.write( config_data ) return def main(): starting_time = time() ip_list = read_device_excel() for ipaddr in ip_list: hwconfig = get_config(ipaddr) write_config_to_file(hwconfig,ipaddr) print ('\n---- End get config threading, elapsed time=', time() - starting_time) #======================================== # Get config of HUAWEI #======================================== if __name__ == '__main__': main() 加一段gevent,def run_gevent()
好的,可以尝试这样写:
```
#!/usr/bin/env python
#coding: utf-8
import os
from time import time
from datetime import datetime
from netmiko import ConnectHandler
from openpyxl import Workbook
from openpyxl import load_workbook
import gevent
from gevent import monkey
monkey.patch_all()
def read_device_excel():
ip_list = []
wb1 = load_workbook('E:\/Users/Wayne_Peng/Desktop/cs_lab.xlsx')
ws1 = wb1.get_sheet_by_name("Sheet1")
for cow_num in range(2,ws1.max_row+1):
ipaddr = ws1["a"+str(cow_num)].value
ip_list.append(ipaddr)
return ip_list
def get_config(ipaddr):
session = ConnectHandler(device_type="huawei",
ip=ipaddr,
username="mtlops",
password="cisco,123",
banner_timeout=300)
print("connecting to "+ ipaddr)
print ("---- Getting HUAWEI configuration from {}-----------".format(ipaddr))
commands = ['display version', 'display cpu-usage', 'display memory-usage']
config_data = ''
for cmd in commands:
output = session.send_command_timing(cmd)
config_data += f'{cmd}\n{output}\n'
session.disconnect()
return config_data
def write_config_to_file(config_data,ipaddr):
now = datetime.now()
date= "%s-%s-%s"%(now.year,now.month,now.day)
time_now = "%s-%s"%(now.hour,now.minute)
#---- Write out configuration information to file
config_path = 'E:\/Users/Wayne_Peng/Desktop/' +date
verify_path = os.path.exists(config_path)
if not verify_path:
os.makedirs(config_path)
config_filename = config_path+"/"+'config_' + ipaddr +"_"+date+"_" + time_now # Important - create unique configuration file name
print ('---- Writing configuration: ', config_filename)
with open( config_filename, "w",encoding='utf-8' ) as config_out:
config_out.write( config_data )
return
def run_gevent(ip_list):
jobs = []
for ipaddr in ip_list:
jobs.append(gevent.spawn(get_config, ipaddr))
gevent.joinall(jobs)
for job, ipaddr in zip(jobs, ip_list):
hwconfig = job.value
write_config_to_file(hwconfig,ipaddr)
print('\n---- End get config threading')
def main():
starting_time = time()
ip_list = read_device_excel()
run_gevent(ip_list)
print('elapsed time:', time() - starting_time)
#========================================
# Get config of HUAWEI
#========================================
if __name__ == '__main__':
main()
```
注意,这里使用了 `gevent` 库,需要先安装。可以在命令行中使用 `pip install gevent` 进行安装。
#【例8-14】组合图表上下布局。 from pyecharts import options as opts from pyecharts.charts import Bar, Grid, Line,Scatter A = ["小米", "三星", "华为", "苹果", "魅族", "VIVO", "OPPO"] CA = [100,125,87,90,78,98,118] B = ["草莓", "芒果", "葡萄", "雪梨", "西瓜", "柠檬", "车厘子"] CB = [78,95,120,102,88,108,98] bar = Bar() bar.add_xaxis(A) bar.add_yaxis("商家A",CA) bar.add_yaxis("商家B", CB) bar.set_global_opts(title_opts=opts.TitleOpts(title="Grid-Bar")) bar.render_notebook() line=Line() line.add_xaxis(B) line.add_yaxis("商家A", CA) line.add_yaxis("商家B", CB) line.set_global_opts(title_opts=opts.TitleOpts(title="Grid-Line", pos_top="48%"), legend_opts=opts.LegendOpts(pos_top="48%")) line.render_notebook() grid = Grid() grid.add(bar, grid_opts=opts.GridOpts(pos_bottom="60%")) grid.add(line, grid_opts=opts.GridOpts(pos_top="60%")) grid.render_notebook() 做注释
这段代码使用了 pyecharts 库绘制了一个上下布局的组合图表,包括一个柱状图和一条折线图。
首先,定义了两个列表 A 和 B,分别代表两个商家的商品名称。CA 和 CB 分别是这两家商家的销售数据。
然后,使用 Bar 类创建一个柱状图 bar,设置 x 轴为商家名称 A,y 轴分别为商家 A 和 B 的销售数据。设置图表标题为 "Grid-Bar"。
接着,使用 Line 类创建一个折线图 line,设置 x 轴为商家名称 B,y 轴分别为商家 A 和 B 的销售数据。设置图表标题为 "Grid-Line",位置为顶部,同时设置图例位置为顶部。
最后,使用 Grid 类创建一个网格布局 grid,将 bar 和 line 分别加入网格中,设置柱状图在底部,折线图在顶部。对于每一个图表,设置 grid_opts 参数来控制布局的位置。
最后调用 grid.render_notebook() 将图表渲染出来。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)