使用时Series.map,它有什么作用na_action?文档不清楚,我还没有提出结果受参数影响的示例。
尽管文档中的解释非常清楚,但如果您使用以 NaN 作为输入并将其返回为 NaN 的数字函数,则很难看出发生了什么。对于尚未阅读文档的其他人,他们说如果 na_action='ignore' NA 值将不会传递到映射函数,如果 na_action=None (默认值)则它们会传递给映射函数。
这是一个显示差异的简单示例:
import pandas as pd
import numpy as np
s = pd.Series([1, 2, 3, np.nan])
s2 = s.map(lambda x: 'this is a string {}'.format(x), na_action=None)
0 this is a string 1.0
1 this is a string 2.0
2 this is a string 3.0
3 this is a string nan
dtype: object
s3 = s.map(lambda x: 'this is a string {}'.format(x), na_action='ignore')
0 this is a string 1.0
1 this is a string 2.0
2 this is a string 3.0
3 NaN
dtype: object
Run Code Online (Sandbox Code Playgroud)
如果您自己的分析中有更好的示例,您应该考虑在pandas repo上创建一个问题,以改进文档并帮助其他人理解。
| 归档时间: |
|
| 查看次数: |
6221 次 |
| 最近记录: |