小编Mai*_*aik的帖子

Replace values in dataframe column depending on another column with condition

I need to replace values in the dataframe column x. The result should look like x_new. So in detail I have to keep the values in the x column where y is 1 and 255. Between 1 and 255 I must replace the x values with the value where y is 1. The values between 255 and 1 should stay the same. So how can I get the column x_new?

I guess it could work with replace and some condition …

python replace dataframe pandas

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

如何按时间戳对数据帧进行排序

我需要按时间戳对以下数据帧进行排序。我知道这很简单,也许一行代码,但我对 sort_values 或排序索引的所有尝试都失败了。我必须按 id 和时间戳对数据帧进行排序。这是数据框的片段:

 id        timestamp        x_value
2854    2018-01-03 00:05:35 1
2854    2018-01-03 00:05:36 1
2854    2018-01-03 00:05:37 1
2854    2018-01-03 00:05:38 1
2854    2018-01-03 00:05:39 1
2854    2018-01-03 00:05:41 2
2854    2018-01-03 00:05:15 1 
2854    2018-01-03 00:05:42 1
2854    2018-01-03 00:05:14 1
2854    2018-01-03 00:05:12 2
2854    2018-01-03 00:04:47 1
2854    2018-01-03 00:04:48 1
2854    2018-01-03 00:04:49 1
2854    2018-01-03 00:04:51 2
2854    2018-01-03 00:04:52 1
.
.
.
3245    2018-01-02 16:42:25 3
3245    2018-01-02 16:42:22 2
3245 …
Run Code Online (Sandbox Code Playgroud)

python sorting dataframe

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

标签 统计

dataframe ×2

python ×2

pandas ×1

replace ×1

sorting ×1