You can concatenate lat/long after creating the dataframe.
(您可以在创建数据框后并置经/纬度。)
Here's an example: (这是一个例子:)
In [175]: import pandas as pd
In [176]: df = pd.read_csv(r"test.csv")
#null values for location series
In [202]: df
Out[202]:
name location lat long price
0 house A NaN 42.1629 139.4875 250
1 house B NaN 42.1716 139.5140 350
Now concatenate lat/long and assign values to location
:
(现在连接经/纬度并将值分配给location
:)
In [203]: df.location = tuple(zip(df.lat, df.long))
In [204]: df
Out[204]:
name location lat long price
0 house A (42.162913, 139.487541) 42.1629 139.4875 250
1 house B (42.171569, 139.51402) 42.1716 139.5140 350
As gmaps.marker_layer accepts a list of tuples, you can get that for the location
series like this:
(当gmaps.marker_layer接受一个元组列表时,您可以像以下location
序列那样获取它:)
In [199]: property_locations = df['location'].tolist()
In [200]: property_locations
Out[200]: [(42.162913, 139.487541), (42.171569, 139.51402)]
Now, you can use property_locations
as an argument for gmaps.marker_layer
.
(现在,您可以将property_locations
用作gmaps.marker_layer
的参数。)
Also, info_box_template.format()
requires a dictionary mapping.
(另外, info_box_template.format()
需要字典映射。)
Thus, we must transform the dataframe df
to a list of dict's first: (因此,我们必须将数据帧df
转换为dict的第一个列表:)
In [19]: df_dict = df.to_dict('records')
In [20]: df_dict
Out[20]:
[{'lat': 42.162913,
'location': (42.162913, 139.487541),
'long': 139.487541,
'name': 'house A',
'price': 250},
{'lat': 42.171569,
'location': (42.171569, 139.51402),
'long': 139.51402,
'name': 'house B',
'price': 350}]
Now, use df_dict
like below to get house info for each house:
(现在,使用如下所示的df_dict
获取每个房屋的房屋信息:)
In [21]: house_info = [info_box_template.format(**house) for house in df_dict]
In [22]: house_info
Out[22]:
['
<dl>
<dt>Property Name</dt><dd>house A</dd>
<dt>Priced from $ </dt><dd>250</dd>
</dl>
',
'
<dl>
<dt>Property Name</dt><dd>house B</dd>
<dt>Priced from $ </dt><dd>350</dd>
</dl>
']