我正在运行以下代码以尝试在pycharm上ping服务器:
import subprocess as sp
ip = "216.52.241.254"
status,result = sp.getstatusoutput("ping -c1 -w2 " + ip)
if status == 0:
print("System " + ip + " is UP !")
else:
print("System " + ip + " is DOWN !")
print(result)
Run Code Online (Sandbox Code Playgroud)
但是,该print(result)
行始终会打印"Access denied. Option -c1 requires administrative privileges."
。我尝试以管理员身份运行pycharm,但是没有任何影响。如何授予文件管理员权限?
我有一个数据框和一个我想合并的字典,以便字典在它们的键相交时覆盖数据框
令人沮丧的方法:
import pandas as pd
# setup input df
d1 = pd.DataFrame([[1, 2], [5, 6]])
d1.columns = ['a', 'b']
d1 = d1.set_index('a')
# setup input dict
a = {1 : 3, 2: 3}
# Now how do we join?
# ~~~~~~~~~~~~~~~~~~~
# turn dict into dataframe
d2 = pd.DataFrame()
d2 = d2.from_dict(a, orient='index')
d2.columns = d1.columns
# update indices that are the same
d2.update(d1)
# append indices that are different
d2 = d2.append(d1.loc[d1.index.difference( d2.index ) ])
d2
Run Code Online (Sandbox Code Playgroud) 我有一个数据框,它汇总了几天的数据.我想补充一下缺少的日子
我正在关注另一篇文章,将失踪日期添加到pandas数据框中,不幸的是,它覆盖了我的结果(可能功能稍有改变?)...代码如下
import random
import datetime as dt
import numpy as np
import pandas as pd
def generate_row(year, month, day):
while True:
date = dt.datetime(year=year, month=month, day=day)
data = np.random.random(size=4)
yield [date] + list(data)
# days I have data for
dates = [(2000, 1, 1), (2000, 1, 2), (2000, 2, 4)]
generators = [generate_row(*date) for date in dates]
# get 5 data points for each
data = [next(generator) for generator in generators for _ in range(5)]
df = …
Run Code Online (Sandbox Code Playgroud) 我试图做一个简单的键盘记录测试,但我的程序没有按预期工作,我不知道为什么。
在我的程序中,我有一个低级键盘钩子,并为其附加了一个简单的过程。该过程只是打开/创建一个文件并写入“Hello World”然后关闭。但是它没有创建文件,可能是因为我的过程不正确或者因为我的钩子没有正确建立。
代码:
#include<windows.h>
#include<stdio.h>
#include <iostream>
#include <fstream>
using namespace std;
LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam){
ofstream myfile;
myfile.open ("[PATH]/example.txt");
myfile << "Hello world";//((KBDLLHOOKSTRUCT *)lParam)->vkCode
myfile.close();
return CallNextHookEx(NULL,code,wParam,lParam);
}
int main(void){
HINSTANCE hInst = NULL;
HHOOK hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, hInst, 0);
printf("HHOOK is not null: %s\n", (hHook != NULL) ? "True" : "False");
char q;
for (cout << "q to quit\n"; q != 'q'; cin >> q);
printf("Successfully unhooked: %s", UnhookWindowsHookEx(hHook) ? "True" : …
Run Code Online (Sandbox Code Playgroud)