不确定我的datetime列是否是字符串,或者它是怎么回事。
好吧,我尝试过按数量排序,然后按日期时间排序,但是从来没有做对。
输入
print("kimera1")
#with pd.option_context('display.max_rows', None, 'display.max_columns', None): # more options can be specified also
print(kimera)
kimera = kimera.sort_values(by='quantity',ascending=False)
print("kimera2")
print(kimera)
kimera = kimera.sort_values(by='date',ascending=True)
print("kimera3")
print(kimera)
输出
kimera1
client_id date ... type_id unit_price
0 2114499871 2019-07-09T21:38:15+00:00 ... 37483 8.560000e+07
1 97005654 2019-07-09T08:07:57+00:00 ... 38 3.999900e+02
2 96644839 2019-07-07T02:02:45+00:00 ... 37457 2.900000e+07
3 2113806433 2019-07-06T18:13:12+00:00 ... 37482 7.300000e+07
4 1240358507 2019-07-05T19:38:20+00:00 ... 11381 4.399900e+07
5 97005654 2019-07-05T04:12:23+00:00 ... 38 3.999900e+02
6 97005654 2019-07-05T02:49:26+00:00 ... 38 3.999900e+02
7 1857838543 2019-07-03T20:08:15+00:00 ... 37482 6.900000e+07
8 92337897 2019-07-03T14:44:32+00:00 ... 11365 4.480000e+07
9 2114793091 2019-07-01T23:04:26+00:00 ... 12044 3.000000e+07
10 95826459 2019-06-30T07:22:45+00:00 ... 37482 1.190000e+08
11 94904480 2019-06-30T01:31:01+00:00 ... 11186 3.717800e+07
12 2113704258 2019-06-29T10:46:53+00:00 ... 12044 3.399700e+07
13 2115385566 2019-06-27T12:07:58+00:00 ... 11393 4.490000e+07
14 1732767131 2019-06-27T09:22:24+00:00 ... 38 3.252400e+02
15 93204128 2019-06-26T20:47:01+00:00 ... 11198 3.600000e+07
16 90216786 2019-06-25T23:51:48+00:00 ... 11172 3.600000e+07
17 91205905 2019-06-25T19:59:21+00:00 ... 16275 6.000000e+02
18 2113996003 2019-06-25T16:52:14+00:00 ... 11190 4.000000e+07
19 96345205 2019-06-25T16:39:49+00:00 ... 16275 6.000000e+02
20 95103814 2019-06-25T01:16:28+00:00 ... 11202 3.000000e+07
21 543983309 2019-06-24T14:05:49+00:00 ... 11172 2.741538e+07
22 2114159703 2019-06-23T21:20:04+00:00 ... 34 6.300000e+00
23 2114159703 2019-06-23T15:28:37+00:00 ... 16274 8.500000e+02
24 1872130440 2019-06-23T10:02:21+00:00 ... 11400 3.849900e+07
25 2112790910 2019-06-23T00:00:46+00:00 ... 11202 2.839450e+07
26 2115326382 2019-06-22T22:42:00+00:00 ... 11371 3.715019e+07
27 96768321 2019-06-22T17:02:14+00:00 ... 37481 8.900000e+07
28 1009077082 2019-06-21T23:35:03+00:00 ... 11379 4.200000e+07
29 755876330 2019-06-21T12:27:59+00:00 ... 11186 3.717800e+07
30 1556713165 2019-06-20T23:27:23+00:00 ... 11393 3.699800e+07
31 513171897 2019-06-19T15:58:51+00:00 ... 11381 4.381799e+07
32 96711003 2019-06-18T17:50:15+00:00 ... 11198 3.700000e+07
33 408059764 2019-06-18T15:36:49+00:00 ... 11172 3.500000e+07
34 1276544138 2019-06-17T21:32:47+00:00 ... 11379 4.100000e+07
35 94184713 2019-06-17T03:30:26+00:00 ... 37481 8.700000e+07
36 2113441660 2019-06-16T04:12:59+00:00 ... 37458 3.494900e+07
37 755284989 2019-06-15T19:54:44+00:00 ... 37458 3.500000e+07
38 1731319339 2019-06-13T12:00:14+00:00 ... 11379 4.200000e+07
39 96053157 2019-06-12T04:07:15+00:00 ... 37483 8.550000e+07
40 1690931127 2019-06-12T00:44:40+00:00 ... 37482 6.170000e+07
41 92812153 2019-06-11T05:23:09+00:00 ... 37460 3.650000e+07
42 2114791711 2019-06-10T16:14:59+00:00 ... 11371 4.150000e+07
43 1547875730 2019-06-10T15:22:53+00:00 ... 17887 9.999900e+02
44 227535700 2019-06-10T15:12:06+00:00 ... 16272 5.445000e+02
45 95165645 2019-06-10T06:32:52+00:00 ... 11393 5.399000e+07
46 1859791498 2019-06-10T05:35:57+00:00 ... 22460 6.200000e+07
47 2112629749 2019-06-09T15:46:46+00:00 ... 2549 1.800000e+06
48 94391975 2019-06-08T00:06:12+00:00 ... 37460 3.650000e+07
49 91521700 2019-06-07T14:11:45+00:00 ... 11393 4.999800e+07
50 1171184159 2019-06-06T18:10:19+00:00 ... 12044 3.399800e+07
51 96410073 2019-06-05T17:32:01+00:00 ... 11371 4.700000e+07
[52 rows x 10 columns]
kimera2
client_id date ... type_id unit_price
22 2114159703 2019-06-23T21:20:04+00:00 ... 34 6.300000e+00
44 227535700 2019-06-10T15:12:06+00:00 ... 16272 5.445000e+02
43 1547875730 2019-06-10T15:22:53+00:00 ... 17887 9.999900e+02
19 96345205 2019-06-25T16:39:49+00:00 ... 16275 6.000000e+02
17 91205905 2019-06-25T19:59:21+00:00 ... 16275 6.000000e+02
23 2114159703 2019-06-23T15:28:37+00:00 ... 16274 8.500000e+02
14 1732767131 2019-06-27T09:22:24+00:00 ... 38 3.252400e+02
5 97005654 2019-07-05T04:12:23+00:00 ... 38 3.999900e+02
6 97005654 2019-07-05T02:49:26+00:00 ... 38 3.999900e+02
1 97005654 2019-07-09T08:07:57+00:00 ... 38 3.999900e+02
34 1276544138 2019-06-17T21:32:47+00:00 ... 11379 4.100000e+07
35 94184713 2019-06-17T03:30:26+00:00 ... 37481 8.700000e+07
38 1731319339 2019-06-13T12:00:14+00:00 ... 11379 4.200000e+07
33 408059764 2019-06-18T15:36:49+00:00 ... 11172 3.500000e+07
36 2113441660 2019-06-16T04:12:59+00:00 ... 37458 3.494900e+07
37 755284989 2019-06-15T19:54:44+00:00 ... 37458 3.500000e+07
32 96711003 2019-06-18T17:50:15+00:00 ... 11198 3.700000e+07
0 2114499871 2019-07-09T21:38:15+00:00 ... 37483 8.560000e+07
40 1690931127 2019-06-12T00:44:40+00:00 ... 37482 6.170000e+07
39 96053157 2019-06-12T04:07:15+00:00 ... 37483 8.550000e+07
30 1556713165 2019-06-20T23:27:23+00:00 ... 11393 3.699800e+07
41 92812153 2019-06-11T05:23:09+00:00 ... 37460 3.650000e+07
42 2114791711 2019-06-10T16:14:59+00:00 ... 11371 4.150000e+07
45 95165645 2019-06-10T06:32:52+00:00 ... 11393 5.399000e+07
46 1859791498 2019-06-10T05:35:57+00:00 ... 22460 6.200000e+07
47 2112629749 2019-06-09T15:46:46+00:00 ... 2549 1.800000e+06
48 94391975 2019-06-08T00:06:12+00:00 ... 37460 3.650000e+07
49 91521700 2019-06-07T14:11:45+00:00 ... 11393 4.999800e+07
50 1171184159 2019-06-06T18:10:19+00:00 ... 12044 3.399800e+07
31 513171897 2019-06-19T15:58:51+00:00 ... 11381 4.381799e+07
26 2115326382 2019-06-22T22:42:00+00:00 ... 11371 3.715019e+07
29 755876330 2019-06-21T12:27:59+00:00 ... 11186 3.717800e+07
12 2113704258 2019-06-29T10:46:53+00:00 ... 12044 3.399700e+07
2 96644839 2019-07-07T02:02:45+00:00 ... 37457 2.900000e+07
3 2113806433 2019-07-06T18:13:12+00:00 ... 37482 7.300000e+07
4 1240358507 2019-07-05T19:38:20+00:00 ... 11381 4.399900e+07
7 1857838543 2019-07-03T20:08:15+00:00 ... 37482 6.900000e+07
8 92337897 2019-07-03T14:44:32+00:00 ... 11365 4.480000e+07
9 2114793091 2019-07-01T23:04:26+00:00 ... 12044 3.000000e+07
10 95826459 2019-06-30T07:22:45+00:00 ... 37482 1.190000e+08
11 94904480 2019-06-30T01:31:01+00:00 ... 11186 3.717800e+07
13 2115385566 2019-06-27T12:07:58+00:00 ... 11393 4.490000e+07
28 1009077082 2019-06-21T23:35:03+00:00 ... 11379 4.200000e+07
15 93204128 2019-06-26T20:47:01+00:00 ... 11198 3.600000e+07
16 90216786 2019-06-25T23:51:48+00:00 ... 11172 3.600000e+07
18 2113996003 2019-06-25T16:52:14+00:00 ... 11190 4.000000e+07
20 95103814 2019-06-25T01:16:28+00:00 ... 11202 3.000000e+07
21 543983309 2019-06-24T14:05:49+00:00 ... 11172 2.741538e+07
24 1872130440 2019-06-23T10:02:21+00:00 ... 11400 3.849900e+07
25 2112790910 2019-06-23T00:00:46+00:00 ... 11202 2.839450e+07
27 96768321 2019-06-22T17:02:14+00:00 ... 37481 8.900000e+07
51 96410073 2019-06-05T17:32:01+00:00 ... 11371 4.700000e+07
[52 rows x 10 columns]
kimera3
client_id date ... type_id unit_price
0 2114499871 2019-07-09T21:38:15+00:00 ... 37483 8.560000e+07
1 97005654 2019-07-09T08:07:57+00:00 ... 38 3.999900e+02
2 96644839 2019-07-07T02:02:45+00:00 ... 37457 2.900000e+07
3 2113806433 2019-07-06T18:13:12+00:00 ... 37482 7.300000e+07
4 1240358507 2019-07-05T19:38:20+00:00 ... 11381 4.399900e+07
5 97005654 2019-07-05T04:12:23+00:00 ... 38 3.999900e+02
6 97005654 2019-07-05T02:49:26+00:00 ... 38 3.999900e+02
7 1857838543 2019-07-03T20:08:15+00:00 ... 37482 6.900000e+07
8 92337897 2019-07-03T14:44:32+00:00 ... 11365 4.480000e+07
9 2114793091 2019-07-01T23:04:26+00:00 ... 12044 3.000000e+07
10 95826459 2019-06-30T07:22:45+00:00 ... 37482 1.190000e+08
11 94904480 2019-06-30T01:31:01+00:00 ... 11186 3.717800e+07
12 2113704258 2019-06-29T10:46:53+00:00 ... 12044 3.399700e+07
13 2115385566 2019-06-27T12:07:58+00:00 ... 11393 4.490000e+07
14 1732767131 2019-06-27T09:22:24+00:00 ... 38 3.252400e+02
15 93204128 2019-06-26T20:47:01+00:00 ... 11198 3.600000e+07
16 90216786 2019-06-25T23:51:48+00:00 ... 11172 3.600000e+07
17 91205905 2019-06-25T19:59:21+00:00 ... 16275 6.000000e+02
18 2113996003 2019-06-25T16:52:14+00:00 ... 11190 4.000000e+07
19 96345205 2019-06-25T16:39:49+00:00 ... 16275 6.000000e+02
20 95103814 2019-06-25T01:16:28+00:00 ... 11202 3.000000e+07
21 543983309 2019-06-24T14:05:49+00:00 ... 11172 2.741538e+07
22 2114159703 2019-06-23T21:20:04+00:00 ... 34 6.300000e+00
23 2114159703 2019-06-23T15:28:37+00:00 ... 16274 8.500000e+02
24 1872130440 2019-06-23T10:02:21+00:00 ... 11400 3.849900e+07
25 2112790910 2019-06-23T00:00:46+00:00 ... 11202 2.839450e+07
26 2115326382 2019-06-22T22:42:00+00:00 ... 11371 3.715019e+07
27 96768321 2019-06-22T17:02:14+00:00 ... 37481 8.900000e+07
28 1009077082 2019-06-21T23:35:03+00:00 ... 11379 4.200000e+07
29 755876330 2019-06-21T12:27:59+00:00 ... 11186 3.717800e+07
30 1556713165 2019-06-20T23:27:23+00:00 ... 11393 3.699800e+07
31 513171897 2019-06-19T15:58:51+00:00 ... 11381 4.381799e+07
32 96711003 2019-06-18T17:50:15+00:00 ... 11198 3.700000e+07
33 408059764 2019-06-18T15:36:49+00:00 ... 11172 3.500000e+07
34 1276544138 2019-06-17T21:32:47+00:00 ... 11379 4.100000e+07
35 94184713 2019-06-17T03:30:26+00:00 ... 37481 8.700000e+07
36 2113441660 2019-06-16T04:12:59+00:00 ... 37458 3.494900e+07
37 755284989 2019-06-15T19:54:44+00:00 ... 37458 3.500000e+07
38 1731319339 2019-06-13T12:00:14+00:00 ... 11379 4.200000e+07
39 96053157 2019-06-12T04:07:15+00:00 ... 37483 8.550000e+07
40 1690931127 2019-06-12T00:44:40+00:00 ... 37482 6.170000e+07
41 92812153 2019-06-11T05:23:09+00:00 ... 37460 3.650000e+07
42 2114791711 2019-06-10T16:14:59+00:00 ... 11371 4.150000e+07
43 1547875730 2019-06-10T15:22:53+00:00 ... 17887 9.999900e+02
44 227535700 2019-06-10T15:12:06+00:00 ... 16272 5.445000e+02
45 95165645 2019-06-10T06:32:52+00:00 ... 11393 5.399000e+07
46 1859791498 2019-06-10T05:35:57+00:00 ... 22460 6.200000e+07
51 96410073 2019-06-05T17:32:01+00:00 ... 11371 4.700000e+07
50 1171184159 2019-06-06T18:10:19+00:00 ... 12044 3.399800e+07
49 91521700 2019-06-07T14:11:45+00:00 ... 11393 4.999800e+07
48 94391975 2019-06-08T00:06:12+00:00 ... 37460 3.650000e+07
47 2112629749 2019-06-09T15:46:46+00:00 ... 2549 1.800000e+06
[52 rows x 10 columns]
数据最初是按正确的顺序排列的,最新的在顶部,最旧的在底部,这就是数据从服务器中输出的方式。 但是我希望能够将其归类到例如按数量排序的情况。 差不多了,但是最后五个确实搞砸了,不知道为什么。 因此,很显然,如果datatime是字符串,我需要将其转换为正确的pandas.to_datetime,如果我理解正确的话,甚至不确定那是否正确。 如果是正确的话,我不确定如何开始。
答案 0 :(得分:0)
请确保将日期转换为日期时间类型(如果采用字符串格式):
kimera['date'] = pd.to_datetime(kimera['date'], errors='coerce')
然后执行以下操作:
kimera = kimera.sort_values(['quantity', 'date'], ascending = [False, True])