我有一张看起来像这样的桌子
“IP”, “DNS”, “的NetBIOS”, “OS”
“x.x.x”,“name”,“name”,“Windows 2012”
“x.x.x”,“name”,“name”,“HP JetDirect”
我正在尝试使用Pandas找到一种方法让代码看起来在OS列中,如果它等于“Windows”(“Windows”无关紧要之后的任何内容),它将打印“Workstation”这个词,如果它是其他任何东西它将打印“打印机”
我也有这行代码插入新列。但是我需要根据上面的问题知道要打印什么价值
Param([String]$xVariable)
# ...your code here...
$smtp = "smtp.[emaildomain].com"
$to = "[Send to email address]"
$from = "[From email address]"
$subject = "[Subject]"
$body = "[Text you want to include----the <br> is a line feed: <br> <br>]"
$body += "[This could be a second line of text]" + "<br> "
$attachment="[file name if you would like to include an attachment]"
send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml -Attachment $attachment -Priority high
答案 0 :(得分:1)
您可以numpy.where
使用str.contains
:
print (df['OS'].str.contains('Windows'))
0 True
1 False
Name: OS, dtype: bool
#for last column
df['Report Category'] = np.where(df['OS'].str.contains('Windows'), 'Workstation', 'Printer')
print (df)
IP DNS NetBIOS OS Report Category
0 x.x.x name name Windows 2012 Workstation
1 x.x.x name name HP JetDirect Printer
4th
列使用insert
:
df.insert(4,'Report Category', np.where(df['OS'].str.contains('Windows'),
'Workstation', 'Printer'))
print (df)
IP DNS NetBIOS OS Report Category
0 x.x.x name name Windows 2012 Workstation
1 x.x.x name name HP JetDirect Printer