【发布时间】:2016-05-31 00:45:39
【问题描述】:
我正在尝试以下方法:
PoliceStations_raw=pd.DataFrame(
[['BAYVIEW' ,37.729732,-122.397981],
['CENTRAL' ,37.798732,-122.409919],
['INGLESIDE' ,37.724676,-122.446215],
['MISSION' ,37.762849,-122.422005],
['NORTHERN' ,37.780186,-122.432467],
['PARK' ,37.767797,-122.455287],
['RICHMOND' ,37.779928,-122.464467],
['SOUTHERN' ,37.772380,-122.389412],
['TARAVAL' ,37.743733,-122.481500],
['TENDERLOIN',37.783674,-122.412899]],columns=['PdDistrict','XX','YY'])
df1=pd.DataFrame([[0,'CENTRAL'],[1,'TARAVAL'],[3,'CENTRAL'],[2,'BAYVIEW']])
df1.columns = ['Index','PdDistrict']
Index PdDistrict
0 0 CENTRAL
1 1 TARAVAL
2 3 CENTRAL
3 2 BAYVIEW
尽管输入了sort=False,但返回的对象已合并表,但使用PdDistrict 作为索引,并更改了原始左侧数据帧的行顺序。
pd.merge(df1,PoliceStations_raw,sort=False)
return this(注意PdDistrict的顺序已经改变)
Index PdDistrict XX YY
0 0 CENTRAL 37.798732 -122.409919
1 3 CENTRAL 37.798732 -122.409919
2 1 TARAVAL 37.743733 -122.481500
3 2 BAYVIEW 37.729732 -122.397981
【问题讨论】: