python - 读取 row_python 中的每个字符串
问题描述
如何使用它作为分隔符“|”分割每个单词 然后将每个单词作为避免重复的键发送?我使用了这个,但它不起作用:
for row in df.elements.itertuples():
for l in row.elements.split("|"):
list_elem.send_keys(l)
解决方案
根据需要修改:
#for each row in the frame
for index, row in df.iterrows():
#if blank skip it
if row['elements'] == '':
continue
#if '|' isn't in the string skip it too
elif '|' not in row['elements']:
continue
else:
#split the string into a list by the the '|' char
l = row['elements'].split('|')
#remove whitespace from the beginning and end of each item
l = [x.strip() for x in l]
#for each item in the list
for i, item in enumerate(l):
#if the first item
if i == 0:
#send; print for testing
print(item)
#if not the first item
else:
#send; print (for testing) first and current item;
#break this into two lines if required
print(l[0], item)
输出:
Plastica
Plastica plastica
Plastica plastic
Metallo
Metallo metallo
Acciaio inossidabile
Acciaio inossidabile acciaio inossidabile
Acciaio inossidabile acciaio
Acciaio inossidabile albero della gomma
推荐阅读
- node.js - 使用 AWS 开发工具包将文件上传到存储桶中的特定文件夹
- python - 校准立体相机时出错
- node.js - 每页创建一个新的 node.js 进程
- list - wxMaxima - 如何将变量移交给块内的makelist?
- python - Sympy extend() 方法丢失元素属性
- javascript - 将空格视为字符?
- python - 没有这样的表:Schedule_playerweightlifting
- ios - 强制更新子视图控制器的 safeAreaInsets
- c# - 返回 Task 给出错误的异步方法不能有 ref 或 out 参数
- angular - 带有 Canvas drawImage 的 Angular 5 未显示