从熊猫数据框更新一行

时间:2020-09-23 23:44:30

标签: python pandas

我有以下.csv文件,我想阅读该文件并可能修改其中的某些字段。我的csv文件如下所示:

0   id name    value1 value2
1   .. ..      0       0
2   .. ramon   0       0
3   .. ..      0       0
4   .. ..      0       0
5   .. ..      0       0

我想从名称为ramon的行中修改value2。因此,我做了以下事情:

df = pandas.read_csv('temp.csv', error_bad_lines=False)
df[(df.name == "ramon")]['value2'] = 10

显然,我不能以这种方式修改值。如何正确更新此行的value2字段?

1 个答案:

答案 0 :(得分:2)

您非常接近。您正在寻找<?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $descs = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("file", "error.txt", "w") ); $cmd = "/bin/bash"; $proc = proc_open($cmd, $descs, $pipe, NULL); stream_set_blocking($pipe[0], 0); stream_set_blocking($pipe[1], 0); if(!$proc) { $error_file = fopen("error.txt", "r"); echo "Error !" . fread($error_file, filesize($error_file)); fclose($error_file); exit(); } $status = proc_get_status($proc); print_r($status); if(is_resource($proc)) { $commands = ["id", "whoami", "ls"]; $n = 0; $output = ""; while($n < 3) { echo $commands[$n]; usleep(1000); fwrite($pipe[0], $commands[$n] . PHP_EOL ); fflush($pipe[0]); usleep(1000); while($out = stream_get_contents($pipe[1]) && !feof($pipe[1])){ $output .= $out ; } echo $output; $n++; } } ?> 方法:

.loc