记录Powershell作业结果(Logging Powershell Job Results)
我创建了一个基本上收集信息的PowerShell界面,然后通过Start-Job将该信息发送到外部PS脚本。 我有一个计时器,每秒都会触发接收作业,并使用我创建的作业中的STDOUT更新输出框。
外部PS脚本:
该脚本具有许多功能(利用许多cmdlet),并将通过Write-Verbose将消息打印到日志中。 问题是,有时在这些函数中我会打印消息和/或返回一个值。
众所周知,函数返回的任何内容都放置在标准输出中。 因此,只要函数返回一个值,该值就会打印到输出Rich Textbox控件中。 我不想那样。 此外,如果我正在使用VERBOSE,则消息不会被打印在控件中(但是,它正在打印到控制台)
我想要什么 :只将消息打印到我的富文本框和我的日志文件中,流中没有函数返回值(除非它们是消息本身的一部分)。
注意 :我正在将这个应用程序从VB.NET应用程序重写到Powershell Studio应用程序......并且我注意到之前这是通过使用类似的外部PowerShell脚本将STD输出流式传输到文本框中来完成的 - 除了该脚本正在使用WRITE-HOST。 这对我来说没有意义,因为写主机甚至不应该放入流中。
替代方法 :
我有一个工作示例,让作业添加到日志本身,然后让UI运行Get-Content -tail 1 ...这将工作,除了我的一些消息将被打印在多行上,并且它不会像预期的那样拉一切。 如果有人有办法让我在任何时候都能在日志中获得任意数量的新行,请告诉我。 这可能比我目前的方法更容易。
I have created a powershell interface which essentially collects information and then sends that info to an external PS script via Start-Job. I have a timer that triggers recieve-job every second, and updates an output box with STDOUT from the job I created.
External PS Script:
This script has many functions (which utilize many cmdlets), and will be printing messages via Write-Verbose to a log. The issue is, sometimes in these functions I print messages and/or also return a value.
As we all know, anything that a function returns is placed into standard output. So anytime a function returns a value, that value is printed into the Output Rich Textbox control. I don't want that. Also, if I am using VERBOSE, the message is not being printed in the control (however, it is being printed to the console)
What I want: Print only messages to my rich text box AND my log file, with no function return values in the stream (unless they are apart of a message itself).
Note: I am re-writing this application from a VB.NET app, to a Powershell Studio app... and I noticed previously this was being done by streaming STD Output into the text box, using a similar external powershell script--except that script was using WRITE-HOST. That doesn't make sense to me, as write-host isn't even supposed to be put into the stream.
Alternative Approach:
I had a working example of letting the Job add to the log itself, and then having the UI run Get-Content -tail 1... This WOULD WORK, except that some of my messages will be printed on more than one line, and it wouldn't pull everything as expected. If anyone has a way for me to get any X number of new lines in the log at all times, let me know. That might be easier than my current approach.
原文:https://stackoverflow.com/questions/40598414
最满意答案
您可以使用:
>>> df['col2'].str.get_dummies(sep=',') A B C G 0 1 1 0 0 1 1 0 1 1 2 0 1 0 0
加入数据框:
>>> pd.concat([df, df['col2'].str.get_dummies(sep=',')], axis=1) col1 col2 A B C G 0 6 A,B 1 1 0 0 1 15 C,G,A 1 0 1 1 2 25 B 0 1 0 0
You can use:
>>> df['col2'].str.get_dummies(sep=',') A B C G 0 1 1 0 0 1 1 0 1 1 2 0 1 0 0
To join the Dataframes:
>>> pd.concat([df, df['col2'].str.get_dummies(sep=',')], axis=1) col1 col2 A B C G 0 6 A,B 1 1 0 0 1 15 C,G,A 1 0 1 1 2 25 B 0 1 0 0
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
您可以使用: >>> df['col2'].str.get_dummies(sep=',') A B C G 0 1 1 0 0 1 1 0 1 1 2 0 1 0 0 加入数据框: >>> pd.concat([df, df['col2'].str.get_dummies(sep=',')], axis=1) col1 col2 A B C G 0 6 A,B 1 1 0 0 1 15 C,G,A 1 0 1 1 ...
-
我试图复制你的代码,我的工作正常。 data = {'a': ['foo', 'buzz'], 'b':['cookie', 'milk'], 'Price': ['super', ...: 'duper']} x = df.loc[df['Price'].notnull(), ['a', 'b']] >>> a b 0 foo cookie 1 buzz milk xtr = pd.get_dummies(data=x, columns = x.colum ...
-
据我所知,目前没有自动程序来做这件事。 在将来发布的sklearn CategoricalEncoder对于这项工作将非常方便。 如果你克隆sklearn github master分支并自己构建,你已经可以掌握它了。 目前我有两种选择: 使用LabelEncoder+OneHotEncoder组合,请参阅此答案,例如 ; 只需在培训OHE输出后检索(并在需要时存储)列的列表。 然后在测试集/示例上运行pd.get_dummies 。 循环输出测试OHE列,删除那些未出现在训练OHE中的并添加那些在填充零的 ...
-
它可以在没有连接的情况下完成,使用具有所需参数的get_dummies() In [294]: pd.get_dummies(df, prefix=['A', 'D'], columns=['A', 'D']) Out[294]: B C A_x A_y D_j D_l 0 z 1 1.0 0.0 1.0 0.0 1 u 2 0.0 1.0 0.0 1.0 2 z 3 1.0 0.0 1.0 0.0 It can be done without con ...
-
对于你的问题的第一部分,每个虚拟变量被认为是一个独特的特征(以你的12个月假人为例,它将产生11/12虚拟变量。以Jan为基准常数,其他11个虚拟变量的系数告诉你关于特定月份的平均常数是否与Jan不同,因此RFE为您选择两个月的虚拟特征是完全合理的。 但是,由于您在RFE使用默认的LinearRegression ,并且RFE使用.coef_来对要素重要性进行排名,因此您应该设置LinearRegression(normalize=True) 。 否则,基于线性回归系数选择特征是没有意义的。 For the ...
-
尝试这个: import pandas as pd Dict1 = {'str1A':'file1', 'str1B':'file1', 'str1C':'file1', 'str1D':'file1', 'str2A':'file2', 'str2B':'file2', 'str2C':'file2', 'str2D':'file2', 'str2D':'file2', 'str3A':'file3', 'str3B':'file3','str3C':'file3', 'str3D':'file3', ...
-
Python Pandas get_dummies()限制。(Python Pandas get_dummies() limitation. Doesnt convert all columns)[2022-09-12]
它似乎对我有用。 考虑随机3个字符串的系列 import pandas as pd import numpy as np from string import lowercase np.random.seed([3,1415]) s = pd.DataFrame(np.random.choice(list(lowercase), (10000, 3))).sum(1) s.nunique() 7583 然后分配数据帧df df = s.str.get_dummies() df.shape (10 ... -
import pandas as pd df = pd.DataFrame({'Name': ['Curly', 'Moe', 'Larry'], 'Fruit': [['Apple'], ['Orange'], ['Apple', 'Banana']]}, columns=['Name', 'Fruit']) # a one-liner... that's pretty long dummies_df = pd.get_ ...