我想删除pop95和pdenpavg列中可用的负值,并将这些负值保存到单独的数据集中,并将其从原始数据集中删除。
我尝试了以下代码,但是它显示了一个空数据集,而原始数据集清楚地显示了其中的一些负值。
df3 = df2[(df2['pop95']<0) & (df2['pdenpavg']<0)]
df3
答案 0 :(得分:0)
<?php
function checkProxyList_multi($proxy_list, $timeout) {
$proxies = $proxy_list; // Get each proxy
$checked_proxy = array(); // Array containing checked proxies
$mh = curl_multi_init();
$j = 0;
for($i = 0; $i < count($proxies) - 1; $i++) {
if(!in_array($proxies[$i], $checked_proxy)) { // If we didn't checked that proxy, check it
$checked_proxy[$j] = $proxies[$i];
$ch[$j] = curl_init("http://google.com");
curl_setopt($ch[$j], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch[$j], CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch[$j], CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch[$j], CURLOPT_PROXY, $proxies[$i]);
curl_setopt($ch[$j], CURLOPT_NOBODY, true);
curl_multi_add_handle($mh, $ch[$j]);
$j++;
}
}
do {
$execReturnValue = curl_multi_exec($mh, $runningHandles);
} while ($execReturnValue == CURLM_CALL_MULTI_PERFORM);
// Loop and continue processing the request
while ($runningHandles && $execReturnValue == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
usleep(1000);
}
do {
$execReturnValue = curl_multi_exec($mh, $runningHandles);
} while ($execReturnValue == CURLM_CALL_MULTI_PERFORM);
}
// Check for any errors
if ($execReturnValue != CURLM_OK) {
echo "Curl multi read error $execReturnValue\n";
}
// Extract the content
foreach($checked_proxy as $i => $url) {
// Check for errors
$curlError = curl_error($ch[$i]);
if ($curlError == "") {
$res[$i] = curl_multi_getcontent($ch[$i]);
} else {
echo "Curl error on handle $i: $curlError\n";
}
// Remove and close the handle
curl_multi_remove_handle($mh, $ch[$i]);
curl_close($ch[$i]);
}
// Clean up the curl_multi handle
curl_multi_close($mh);
// Print the response data
print_r($res);
}
$proxy_list = array(
'103.242.13.69:8082',
'103.67.165.62:8080',
'103.251.225.4:35101',
'104.148.46.2:3121',
'107.179.7.2:3129',
'104.236.54.196:8080',
);
checkProxyList_multi($proxy_list, 10);
不会有任何变化,但是生成df2
的代码看起来不错。
是否要在此处执行“与”而不是“或”。我怀疑可能是因为没有这样的行,“ pop95”和“ pdenpavg”值同时为负。
答案 1 :(得分:0)
尝试使用:
df3 = df2[(df2['pop95']<0) & (df2['pdenpavg']<0)]
df2 = df2.drop(df3.copy().index)