擅长:python、mysql、java
<p>不确定这是否是最好的方法,但有一种方法是-</p>
<pre><code>In [26]: before.pivot_table(index=['Email','Person'],columns=['Car'], aggfunc=lambda x: True).fillna(False).reset_index()
Out[26]:
Car Email Person Ford Nissan Toyota
0 jane@example.com Jane False True False
1 john@example.com John True True False
2 mary@example.com Mary True False True
</code></pre>