[英]Compare data frames python matching rows
I have a simple question. 我有一个简单的问题。 I need to compare different trajectories made by different cars. 我需要比较不同汽车的不同轨迹。 So, I have different .csv files of different length containing different routes made by the different cars over the time. 因此,我有不同长度的.csv文件,其中包含不同汽车随时间变化的路线。
import pandas as pd
df = pd.read.csv("car1_route0.csv")
df1 = pd.read.csv("car1_route1.csv")
df =
lat lon
48.787834 11.383918
48.788124 11.384003
48.787849 11.383751
df1 =
48.787834 11.383918
48.788124 11.384003
48.787849 11.383751
48.787849 12.000000
At the end I would like to have a data frame that contains all the points counting the number of time people goes trough that point. 最后,我希望有一个包含所有点的数据框,该点计算了人们经过该点的时间。
out =
lat lon time
48.787834 11.383918 2
48.788124 11.384003 2
48.787849 11.383751 2
48.787849 12.000000 1
concat
your dfs after reading them in, then groupby
on 'lat' and 'lon' and then call size
to return the count, reset_index
to restore your grouped columns and finally rename the generated column 0
to 'time': concat
在阅读这些条款后您的DFS,然后groupby
对“土地增值税”和“结肠”,然后调用size
返回计数, reset_index
恢复您的分组列,最后生成的列重命名0
到“时间”:
In [8]:
merged = pd.concat([df1,df2], ignore_index=True)
merged
Out[8]:
lat lon
0 48.787834 11.383918
1 48.788124 11.384003
2 48.787849 11.383751
3 48.787834 11.383918
4 48.788124 11.384003
5 48.787849 11.383751
6 48.787849 12.000000
In [15]:
merged.groupby(['lat','lon']).size().reset_index().rename(columns={0:'time'})
Out[15]:
lat lon time
0 48.787834 11.383918 2
1 48.787849 11.383751 2
2 48.787849 12.000000 1
3 48.788124 11.384003 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.