用于根据行/列表的长度创建字符串的Python函数
我正在使用 Python 和 SQL Alchemy 来自动执行某些产品分类。本质上,我希望将任何带有项目的 csv 作为行,并将其格式化为 SQL 查询的 case 语句的搜索字符串。
我想用 python 编写一个函数,该函数将测量行(或列表)的长度,并在每个单词之间插入文本,并输出一个字符串,该字符串将输入到 SQL 中以查找这些单词。所附的屏幕截图是我在 Excel 中执行此操作的方式。我确信这对于具有一定串联技能的人来说是相当简单的。
I am using Python and SQL Alchemy to automate some categorizations of products. Essentially I am looking to take any csv with items as the rows and format it into search strings for a case statement of a SQL query.
I want to write a function in python that will measure the length of a row (or list) and insert text in between each of the words and output a string that will feed into SQL to find those words. The screenshot attached is how I've been doing it in excel. I'm sure this is fairly straightforward for someone with some concatenation skills.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您可以从第一列中取出值并将其拆分到一个列表中以获得您想要的结果。
例如:
结果:
Seems to me that you can take the value from your first column and split that in to a list in order to get your desired result.
For example:
Results in: