您会发现两列名称和N-对于大多数条目,名称和N都是相同的
但在某些情况下,当存在名称时,N会丢失,反之亦然
对列进行分组,使k i有一个包含所有值的结果列
示例:
Col1 Col2 value....
Adam nan 334
John nan 56
nan Michael 90结果:
Col1 value....
Adam 334
John 56
Michael 90发布于 2019-05-22 01:01:04
试试这个:
for index, row in df.iterrows() :
if not isinstance(df['col1'][index],str) :
df['col1'][index] = df['col2'][index]知道nan是一个浮点数,如果它发现'col1‘处的值是nan,它将获取'col2’处的值
或使用apply
df['B'] = df.apply(lambda x : x['C'] if not isinstance(x['B'],str) else x['B'] ,axis= 1)
new_df = df.delete('C',axis=1)https://stackoverflow.com/questions/56243070
复制相似问题