原先的位置直接挤掉还是怎么说?
暂时按照挤下去的计算
代码如下:
import pandas as pd
import numpy as np
df_sentence = pd.DataFrame({
"senid": np.arange(10, 17),
"sentence": [
"怎样用pandas实现merge?",
"Python之Numpy详细教程",
"怎么使用Pandas批量拆分与合并Excel文件?",
"怎样使用pandas的map和apply函数?",
"深度学习之tensorflow简介",
"tensorflow和numpy的关系",
"基于sklearn的一些机器学习的代码"
]
})
df_keyword = pd.DataFrame({
"keyid": np.arange(5),
"keyword": ["numpy", "pandas", "matplotlib", "sklearn", "tensorflow"]
})
print(df_sentence)
for idx, row in df_sentence.iterrows():
sentence = row['sentence']
for _idx, _row in df_keyword.iterrows():
if _row['keyword'].lower() in sentence.lower():
row['sentence'] = _idx
df_sentence.loc[idx, 'sentence'] = _idx
print("###############################################")
print(df_sentence)
输出为
senid sentence
0 10 怎样用pandas实现merge?
1 11 Python之Numpy详细教程
2 12 怎么使用Pandas批量拆分与合并Excel文件?
3 13 怎样使用pandas的map和apply函数?
4 14 深度学习之tensorflow简介
5 15 tensorflow和numpy的关系
6 16 基于sklearn的一些机器学习的代码
###############################################
senid sentence
0 10 1
1 11 0
2 12 1
3 13 1
4 14 4
5 15 4
6 16 3
如有问题及时沟通