我有一个字符串列表,我想检查每个字符串是否包含某个子字符串。
问题是:应该允许使用占位符。
例如:我正在搜索"customer-id", "customer id", "customers id" ->我的搜索字符串是这样的:"customer{2}id" (而{2}代表0到2之间的占位符字符数-> )。
当然,这不适用于
teststring.indexof("customer{2}id")
还尝试过:
Dim r as new Regex("customer??id")
但这只会抛出
我在Python中有两个字符串列表。其中一个是所需字符串的列表,另一个是更大的不同字符串列表。例如:
desired = ["cat52", "dog64"]
buf = ["horse101", "elephant5", "dog64", "mouse90", "cat52"]
对于第二个列表是否包含第一个列表中的所有字符串,我需要一个True/False。到目前为止我是这样做的:
if all(element in buf for element in desired)
但是,现
我有一个数据帧,其中的列遵循一定的命名约定。我只想保留那些在标题中有'out‘和'agg’作为前缀的内容。 我已经起草了以下代码来实现这一点。我创建了一个列表,这样我就可以让它成为一个小函数,并为我想要提取的col前缀的任何组合调用它。 prefix = ['out', 'agg']
cols = []
for pref in prefix:
cols = cols + [col for col in df.columns if pref in col]
df = df[cols].dropna(how='all', a
我的head列的每一行中的Pandas字符串都以"binary: [49] "开头,但它返回的是False
all(all(df_ms1[head].str.contains('binary: [49] ')) == True for head in msarray_match)
我测试了df_ms1[head].str.contains('binary:'),,它返回了True。我想知道匹配"binary: [49] "这个词有什么问题?此处是否禁止使用空格、数字或括号?
我有一个Pandas包含75k行文本(大约。(每一行350字符)。我需要搜索在该数据帧中出现的45k子字符串列表。
预期输出是包含作者列表和出现次数的authors_data dict。下面的代码假设我有一个dataframe['text']列和一个名为authors_list的子字符串列表。
authors_data = {}
for author in authors_list:
count = 0
for i, row in df.iterrows():
if author in row.text:
count
这是对这个SO post的后续,它提供了一个在字符串列中替换文本的解决方案。
df‘’range‘=df’‘range’.str.替换( ',‘,'-')
然而,这似乎不适用于双句点或后跟句号的问号。
testList = ['this is a.. test stence', 'for which is ?. was a time']
testDf = pd.DataFrame(testList, columns=['strings'])
testDf['strings'].str.replac
我有一个字符串列,它遵循以下模式:
yariyada up to a maximum of (number)% yariyada
比如,就像这样。
will be granted up to a maximum of 75.5% If less, then nothing
我想要创建另一个列,它提取介于“最大值”和"%“之间的数字。
到目前为止,我只能使用.contains方法检测字符串列是否包含该模式。
如果这是说明的话,在Stata (我是stata用户)中,我将使用regexm将字符串分解为部分,并使用regexs撤回部分。我想知道Pandas是否有类似的或者更好的功能。
谢谢你
我从dataframe转换了一个引用字符串列表。
引用字符串列表
brand_list = ['scurfa', 'seagull', 'seagull', 'seiko']
用于description_list的示例输入1
VINTAGE KING SEIKO 44-9990 Gold Medallion,Manual Winding with mod caseback.Serviced 2019.
用于description_list的示例输入2
Power reserve function at 12; push-pull
我正在尝试将引号“”中的所有单词替换为大写单词,除了pandas列中单词"then“后面的单词:例如:
0 There was a "quick" "brown" fox who "jumped" over the wall then "fell" and broke its "tooth"
输出应为:
0 There was a "QUICK" "BROWN" fox who "JUMPED" over the wall then "fell"