Pandas DataFrame相当于laravel的收藏

时间:2018-09-12 13:48:23

标签: php python laravel pandas dataframe

我正在python 3.6.5上使用熊猫,我希望在DataFrame实例上获得与Laravel中Collection的“ pluck”方法相似的结果。例如:

DataFrame

   one     two
0  beer    wine
1  beer  tomato

PHP Laravel代码:

$plucked = $collection->pluck('two')->toArray();
$print_r($plucked);

>> ['wine', 'tomato']

所需的解决方案(与Python等效):

plucked = df.pluck('two')

我该如何实现?

1 个答案:

答案 0 :(得分:0)

您只需执行以下操作即可在DataFrame列中选择ell条目:

storage_variable = df['Column Name']

因此,在您的情况下,将是:

plucked = df['two']
相关问题