小编Jad*_*Sen的帖子

pandas dataframe字符列为整数

我有我的数据框如下:

+--------------+--------------+----+-----+-------+
|      x1      |      x2      | km | gmm | class |
+--------------+--------------+----+-----+-------+
|  180.9863129 | -0.266379416 | 24 |  19 | T     |
|  52.20132828 |  28.93587875 | 16 |  14 | I     |
| -17.17127419 |  29.97013283 | 17 |  16 | D     |
|  37.28710938 | -69.96691132 |  3 |   6 | N     |
| -132.2395782 |  27.02541733 | 15 |  18 | G     |
| -12.52811623 | -87.90951538 | 22 |   5 | S     | …
Run Code Online (Sandbox Code Playgroud)

python pandas

4
推荐指数
1
解决办法
108
查看次数

Pandas:groupby 列出

我有如下数据:

id  value   time

1   5   2000
1   6   2000
1   7   2000
1   5   2001
2   3   2000
2   3   2001
2   4   2005
2   5   2005
3   3   2000
3   6   2005
Run Code Online (Sandbox Code Playgroud)

我的最终目标是将数据放在如下列表中:

[[5,6,7],[5]] (this is for id 1 grouped by the id and year)
[[3],[3],[4,5]] (this is for id 2 grouped by the id and year)
[[3],[6]] (same logic as above)
Run Code Online (Sandbox Code Playgroud)

我已经使用df.groupby(['id', 'year']). 但在那之后,我无法访问组并以上述格式获取数据。

python pandas

4
推荐指数
2
解决办法
2万
查看次数

这2个程序的时间复杂度

我是复杂性分析的新手.任务是给定像"Code"这样的非空字符串返回类似"CCoCodCode"的字符串.我有这两个程序正在做同样的事情.

计划1:

public String stringSplosion(String str) {
    String result = "";
    for (int i=0; i<str.length(); i++) {
        for(int j=0;j<=i;j++)
            result += str.charAt(j);
    }
    return result;
}
Run Code Online (Sandbox Code Playgroud)

所以,上面的一个很简单,这个程序的复杂度为O(n ^ 2).

计划2:

public String stringSplosion(String str) {
    String result = "";
    // On each iteration, add the substring of the chars 0..i
    for (int i=0; i<str.length(); i++) {
        result = result + str.substring(0, i+1);
    }
    return result;
}
Run Code Online (Sandbox Code Playgroud)

从不同的StackOverflow问题来看,它似乎str.substring()具有O(n)的时间复杂度.在那种情况下,程序2也具有O(n ^ 2)时间复杂度.

我的分析是正确的还是我遗漏了什么?

java string algorithm time-complexity

1
推荐指数
1
解决办法
78
查看次数

标签 统计

pandas ×2

python ×2

algorithm ×1

java ×1

string ×1

time-complexity ×1