擅长:python、mysql、java
<p>您可以使用<strong>合并</strong>将两个数据帧合并为一个:</p>
<pre><code>import pandas as pd
pd.merge(restaurant_ids_dataframe, restaurant_review_frame, on='business_id', how='outer')
</code></pre>
<p>其中<strong>on</strong>指定要连接的两个数据帧中存在的字段名,以及<strong>如何连接
定义其内部/外部/左/右连接,外部使用“来自两个帧的键的并集(SQL:full outer join)。”由于两个数据帧中都有“star”列,因此默认情况下,这将在组合的数据帧中创建两列star_x和star_y。正如@DanAllan在join方法中提到的,您可以通过将其作为kwarg传递来修改合并的后缀。默认值是<code>suffixes=('_x', '_y')</code>。如果你想做像<code>star_restaurant_id</code>和<code>star_restaurant_review</code>这样的事情,你可以:</p>
<pre><code> pd.merge(restaurant_ids_dataframe, restaurant_review_frame, on='business_id', how='outer', suffixes=('_restaurant_id', '_restaurant_review'))
</code></pre>
<p>参数在本<a href="http://pandas.pydata.org/pandas-docs/stable/merging.html#database-style-dataframe-joining-merging">link</a>中有详细说明。</p>