dataframe对一列的apply
时间: 2023-11-18 10:12:58 浏览: 88
pandas apply 函数 实现多进程的示例讲解
在DataFrame中,可以对一列使用apply方法来应用一个函数。例如,通过以下代码可以将函数应用于DataFrame中的列:
```python
df['D'] = df['A'].apply(lambda x: 'yes' if x > 50 else 'no')
```
这将在DataFrame的新列'D'中,根据'A'列的值是否大于50,赋予相应的'yes'或'no'。请注意,在这个例子中,我们将lambda函数应用于'A'列。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [pandas的DataFrame使用apply实现对多列,多行操作](https://blog.csdn.net/weixin_39925939/article/details/121803760)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [Pandas DataFrame新增一列](https://blog.csdn.net/m0_64336020/article/details/122130294)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文