guxingy

原文:https://blog.csdn.net/sscc_learning/article/details/76993816
原文:https://www.cnblogs.com/vamei/archive/2013/03/12/2954938.html
原文:https://blog.csdn.net/weixin_36060730/article/details/80380520



1、效果

处理前:

处理后:


2、处理逻辑

入店来源包含手淘搜索时,把搜索的关键词存到列搜索关键字

3、代码如下

import pandas as pd

df = pd.read_excel(\'test.xlsx\')

# 插入列
col_name = df.columns.tolist()
index = col_name.index(\'入店来源\') + 1
col_name.insert(index, \'搜索关键字\')
df = df.reindex(columns = col_name)

# 修改值
df.loc[df[\'入店来源\'].str.find(\'手淘搜索\') > -1 , \'搜索关键字\'] = df[\'入店来源\'].str.replace(\'手淘搜索\',\'\')
df.loc[df[\'入店来源\'].str.find(\'手淘搜索\') > -1 , \'入店来源\'] = \'手淘搜索\'


# 写入新的Excel中
list_excel = []
list_excel.append(df)

writer = pd.ExcelWriter(\'test2.xlsx\')
pd.concat(list_excel).to_excel(writer,\'sheet1\',index=False)
writer.save()

print(\'ok\')

分类:

技术点:

相关文章:

  • 2022-02-09
  • 2022-12-23
  • 2021-05-20
  • 2021-11-09
  • 2022-12-23
  • 2021-05-14
  • 2022-12-23
  • 2022-01-02
猜你喜欢
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
相关资源
相似解决方案