【发布时间】:2020-11-15 13:45:43
【问题描述】:
您好,我想根据来源的值填写 NaN 值。
我试过np.select,但是这个方法也会覆盖其他正确的值。
landline_area1['area'] = np.select(area_conditions, values)
- 表格概览
source codes area
4 1304 1304 Dover
5 1768 1768 Penrith
6 2077 NaN NaN
7 1225 1225 Bath
8 1142 NaN NaN
- 条件
area_conditions = [
(landline_area1['source'].str.startswith('20')),
(landline_area1['source'].str.startswith('23')),
(landline_area1['source'].str.startswith('24'))]
- 价值观
values = [
'London',
'Southampton / Portsmouth',
'Coventry']
- 预期结果
source codes area
4 1304 1304 Dover
5 1768 1768 Penrith
6 2077 NaN London
7 1225 1225 Bath
8 1142 NaN Sheffield
【问题讨论】:
标签: python python-3.x pandas dataframe missing-data