1
假設我有一個數據幀象下面這樣:大熊貓從數據幀中提取列表
FDT_DATE FFLT_LATITUDE FFLT_LONGITUDE FINT_STAT FSTR_ID
51307 1417390467000 31.2899 121.4845 0 112609
51308 1417390428000 31.2910 121.4859 0 112609
51309 1417390608000 31.2944 121.4857 1 112609
51310 1417390548000 31.2940 121.4850 1 112609
51313 1417390668000 31.2954 121.4886 1 112609
51314 1417390717000 31.2965 121.4937 1 112609
53593 1417390758000 31.2946 121.4940 0 112609
63586 1417390798000 31.2932 121.4960 1 112609
63587 1417390818000 31.2940 121.4966 1 112609
63588 1417390827000 31.2946 121.4974 1 112609
63589 1417390907000 31.2952 121.4986 0 112609
我想在一個折線列表提取位置記錄,意思是提取的具有相同FSTR_ID
並與記錄位置FINT_STAT
等於1:
FSTR_ID FDT_DATE POLYLINE
0 112609 1417390608000 [[31.2944,121.4857],[31.2940,121.4850],[31.2954,121.4886],[31.2965,121.4937]]
1 112609 1417390798000 [[31.2932,121.4960],[31.2940,121.4966],[31.2946, 121.4974]]
我該怎麼做?
原單數據集可以通過該代碼來生成:
import pandas as pd
df = pd.DataFrame({"FDT_DATE":{"0":1417390467000,"1":1417390428000,"2":1417390608000,"3":1417390548000,"4":1417390668000,"5":1417390717000,"6":1417390758000,"7":1417390798000,"8":1417390818000,"9":1417390827000,"10":1417390907000},"FFLT_LATITUDE":{"0":31.2899,"1":31.291,"2":31.2944,"3":31.294,"4":31.2954,"5":31.2965,"6":31.2946,"7":31.2932,"8":31.294,"9":31.2946,"10":31.2952},"FFLT_LONGITUDE":{"0":121.4845,"1":121.4859,"2":121.4857,"3":121.485,"4":121.4886,"5":121.4937,"6":121.494,"7":121.496,"8":121.4966,"9":121.4974,"10":121.4986},"FINT_STAT":{"0":0,"1":0,"2":1,"3":1,"4":1,"5":1,"6":0,"7":1,"8":1,"9":1,"10":0},"FSTR_ID":{"0":112609,"1":112609,"2":112609,"3":112609,"4":112609,"5":112609,"6":112609,"7":112609,"8":112609,"9":112609,"10":112609}})
df = df.sort(['FDT_DATE'])
喜cridnirk,我覺得你的方法是多清楚,但有沒有辦法將原點的FDT_DATE保留在結果中?就像@ragesz所做的一樣...我試着在groupby對象中保留FDT_DATE,但失敗了。 – jjdblast
@jjdblast:答案已更新。 – cridnirk