Используйте reset_index
, затем groupby
и resample
:
df.reset_index(level=0).groupby('computer').resample('4s')['value']\
.sum().to_frame().sort_index(level=1)
ИЛИ
df.reset_index('computer').groupby('computer').resample('4s')['value']\
.sum().to_frame().sort_index(level=1)
Выход:
value
computer time
0 1970-01-01 00:00:00 5
1 1970-01-01 00:00:00 1
2 1970-01-01 00:00:00 5
3 1970-01-01 00:00:00 6
2 1970-01-01 00:00:04 3
3 1970-01-01 00:00:04 4
Вы хотите" popen" функция. Вот пример выполнения команды "ls / и т.д." и вывод к консоли.
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv[] )
{
FILE *fp;
char path[1035];
/* Open the command for reading. */
fp = popen("/bin/ls /etc/", "r");
if (fp == NULL) {
printf("Failed to run command\n" );
exit(1);
}
/* Read the output a line at a time - output it. */
while (fgets(path, sizeof(path)-1, fp) != NULL) {
printf("%s", path);
}
/* close */
pclose(fp);
return 0;
}
Вам нужна своего рода Коммуникация Процесса Интера. Используйте канал или общий буфер.
Обычно, если команда является внешней программой, можно использовать ОС для помощи Вам здесь.
command > file_output.txt
, Таким образом, Ваш код C сделал бы что-то как
exec("command > file_output.txt");
Тогда, можно использовать файл file_output.txt.