使用Inplace Fillna进行熊猫位置索引

时间:2018-12-15 01:41:48

标签: python pandas dataframe indexing series

在回答this question时,我遇到了我不了解的行为。

我试图int main() { int x; printf("Pick the program that should be executed:\n"); printf(" 1. Split text\n Enter an option:\n"); scanf("%d", &x); if (x == 1) { // testing example printf("Write the text you want to use:\n"); char str[100]; fgets(str, 100, stdin); printf("Input was: %s\n", str); char test[] = str; char *left; char *right; // first make a copy left = strcpy(test); // second locate the desired text and split in half right = strstr(left, (str/2)); // third split the string *(right - 1) = '\0'; // print the results printf("Original : %s\nLeft side: %s\nRight side: %s\n\n", test, left, right); // clean up free(left); } return main(); } 的特定列fillnaval2用于包含val3中每个值的第一个实例的行。由于某种原因,使用id的{​​{1}}解决方案似乎无法正常工作,我也不明白为什么。

让我们假设这个输入数据帧:

inplace

所需的输出,填充值为fillna

    id  val1  val2  val3       date
0  102     9   NaN   4.0 2002-01-01
1  102     2   3.0   NaN 2002-03-03
2  103     4   NaN   NaN 2003-04-04
3  103     7   4.0   5.0 2003-08-09
4  103     6   5.0   1.0 2005-02-03

以下是一种有效的解决方案,而-1变体不起作用:

    id  val1  val2  val3       date
0  102     9  -1.0   4.0 2002-01-01
1  102     2   3.0   NaN 2002-03-03
2  103     4  -1.0  -1.0 2003-04-04
3  103     7   4.0   5.0 2003-08-09
4  103     6   5.0   1.0 2005-02-03

我正在使用Python 3.6.5,Pandas 0.23.0,NumPy 1.14.3。

可能这是预期的行为,但我一直无法找到重复项。据我所知,没有涉及链式索引。

0 个答案:

没有答案
相关问题