如果您有多个分支语句,则最好创建一个接受行的函数,然后将其应用于
axis=1。这通常比通过行迭代要快得多。
def func(row): if row['mobile'] == 'mobile': return 'mobile' elif row['tablet'] =='tablet': return 'tablet' else: return 'other'df['combo'] = df.apply(func, axis=1)
欢迎分享,转载请注明来源:内存溢出
如果您有多个分支语句,则最好创建一个接受行的函数,然后将其应用于
axis=1。这通常比通过行迭代要快得多。
def func(row): if row['mobile'] == 'mobile': return 'mobile' elif row['tablet'] =='tablet': return 'tablet' else: return 'other'df['combo'] = df.apply(func, axis=1)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)