我看起来像这样的csv(没有列之间的空格):
id, process_id, name, application_label
2, 384, com.qualcomm.telephony, com.qualcomm.atfwd
6, 0, com.facebook.katana:videoplayer, \N
7, 0, com.facebook.orca:videoplayer, \N
9, 29195, com.wsandroid.suite, McAfee Security
10, 12909, com.life360.android.safetymapd:service, \N
如何以及以哪种方式取代' \ N'在application_label列的name列中的值?
输出应为:
id, process_id, name, application_label
2, 384, com.qualcomm.telephony, com.qualcomm.atfwd
6, 0, com.facebook.katana:videoplayer, com.facebook.katana:videoplayer
7, 0, com.facebook.orca:videoplayer, com.facebook.orca:videoplayer
9, 29195, com.wsandroid.suite, McAfee Security
10, 12909, com.life360.android.safetymapd:service, com.life360.android.safetymapd:service
好奇心:
如果是熊猫数据框,最快的方法是什么? 我做了这样的事情:
for index in df.index:
if df.get_value(index, 'application_label') == r'\N':
df.set_value(index, 'application_label', df.get_value(index, 'name'))
但我能更快地做到这一点吗?
答案 0 :(得分:2)
试试这个,
mask = DF['application_label'] == r'\N'
DF.loc[mask, 'application_label'] = DF['name']