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 …
我需要按时间戳对以下数据帧进行排序。我知道这很简单,也许一行代码,但我对 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)