startswith

Concern with startsWith and multiple patterns in R

时光怂恿深爱的人放手 提交于 2021-02-05 06:27:29
问题 I noticed a problem or a concern with the startsWith() function. The following code displays two different selection. The first one behave normally which is this chunk of code: dt_test <- data.table(a = c("abcd", "poo", "abla", "ba"), id = c(1,2,3, 4)) dt_test[startsWith(a, c("ab", "ao")),id] # [1] 1 3 startsWith(dt_test$a, c("ab", "ao")) # TRUE FALSE TRUE FALSE And if you noticed, this one only selects the first one which is counter intuitive since id 2 and 4 are supposed to be TRUE dt_test

XSLT 1.0 for-each 'starts-with' (with variable length)

心不动则不痛 提交于 2021-01-29 09:35:09
问题 thinking aloud, re approach(es 🤔) Input collection (xml) records being transformed eg for-each Order. With an xml 'exclude' (reference-collection) param, to filter out records, eg only transform (for-each Order) where ( start of) current order/reference is not equal to any Reference in the References collection. For simplicity, Order input example <Orders> <Order number="1"> <!-- Include --> <Reference>AB123</Reference> </Order> <Order number="2"> <!-- Exclude --> <Reference>C3PO</Reference>

Replace values in DataFrame column when they start with string using lambda

不羁的心 提交于 2021-01-04 04:22:50
问题 I have a DataFrame: import pandas as pd import numpy as np x = {'Value': ['Test', 'XXX123', 'XXX456', 'Test']} df = pd.DataFrame(x) I want to replace the values starting with XXX with np.nan using lambda. I have tried many things with replace, apply and map and the best I have been able to do is False, True, True, False. The below works, but I would like to know a better way to do it and I think the apply, replace and a lambda is probably a better way to do it. df.Value.loc[df.Value.str

Replace values in DataFrame column when they start with string using lambda

為{幸葍}努か 提交于 2021-01-04 04:16:17
问题 I have a DataFrame: import pandas as pd import numpy as np x = {'Value': ['Test', 'XXX123', 'XXX456', 'Test']} df = pd.DataFrame(x) I want to replace the values starting with XXX with np.nan using lambda. I have tried many things with replace, apply and map and the best I have been able to do is False, True, True, False. The below works, but I would like to know a better way to do it and I think the apply, replace and a lambda is probably a better way to do it. df.Value.loc[df.Value.str

Replace values in DataFrame column when they start with string using lambda

人盡茶涼 提交于 2021-01-04 04:14:01
问题 I have a DataFrame: import pandas as pd import numpy as np x = {'Value': ['Test', 'XXX123', 'XXX456', 'Test']} df = pd.DataFrame(x) I want to replace the values starting with XXX with np.nan using lambda. I have tried many things with replace, apply and map and the best I have been able to do is False, True, True, False. The below works, but I would like to know a better way to do it and I think the apply, replace and a lambda is probably a better way to do it. df.Value.loc[df.Value.str

Subset dataframe in R based on a list specified in a vector (using a 'starts with' expression or equivalent)

随声附和 提交于 2020-06-17 03:44:22
问题 I am trying to identify any participant taking statins in a dataset of over 1 million rows and subset based on this. I have a vector that includes all the codes for these medications (I've just made a few up for demonstration purposes), and I would next like to create a function that searches through the dataframe and identifies any case that has a medication code that "starts with" any of the characters listed in the df. The df looks like this: ID readcode_1 readcode_2 generic_name 1 1001

Subset dataframe in R based on a list specified in a vector (using a 'starts with' expression or equivalent)

怎甘沉沦 提交于 2020-06-17 03:43:08
问题 I am trying to identify any participant taking statins in a dataset of over 1 million rows and subset based on this. I have a vector that includes all the codes for these medications (I've just made a few up for demonstration purposes), and I would next like to create a function that searches through the dataframe and identifies any case that has a medication code that "starts with" any of the characters listed in the df. The df looks like this: ID readcode_1 readcode_2 generic_name 1 1001

自定义 Azure Table storage 查询过滤条件

落爺英雄遲暮 提交于 2020-04-07 11:38:22
本文是在 Azure Table storage 基本用法 一文的基础上,介绍如何自定义 Azure Table storage 的查询过滤条件。如果您还不太清楚 Azure Table storage 的基本用法,请先移步 前文 。 文章来源: 葡萄城产品技术社区 让我们回到前文中提到的一个问题,如何过滤出 MyLogTable 表中某一天产生的所有日志?在进入细节之前,我们先来回顾一下 MyLogTable 类的设计: internal class MyLogEntity : TableEntity { public MyLogEntity() { } public MyLogEntity(string pkey, string rkey) { this.PartitionKey = pkey; this.RowKey = rkey; } //… } 其中,PartitionKey 用来存放产生日志的年份和月份(例如201607表示2016年7月),RowKey 用来存放产生日志的天和时分秒毫秒(例如160934248492表示16号9点34分…)。 在我们设计的 MyLogTable 中,天信息保存在 RowKey 的前两位。我们要做的就是过滤 RowKey 的前两位,也就是找到所有 RowKey 以”xx”开头的记录。这在字符串操作中称为 StartsWith。遗憾的是现有

python pandas renaming column name startswith

左心房为你撑大大i 提交于 2020-01-15 03:24:38
问题 i have multiple excel files with uniform column names, except for one. One file calls it EndOfMarchStatus, another file calls it EndofAprilStatus, and so on. i need to change the column name to just say EndofMonthStatus. there really is no answer i could find that matches this question. some form of rename command with wildcards or startswith will probably work. things i've tried but did not work are: sheet1df.columns.str.replace('Endof.*', 'EndOfMonthStatus') sheet1df.rename(columns=

Efficiently search for first character of a string in a pandas dataframe

淺唱寂寞╮ 提交于 2020-01-03 05:39:07
问题 I have a pandas data frame column and I need to modify any entry of that column that starts with a 2. Right now, I'm using this which works, but is very, very slow: for i, row in df.iterrows(): if df['IDnumber'][i].startswith('2') == True: '''Do some stuff''' I feel (read: know) there's a more efficent way to do this without using a for loop but I can't seem to find it. Other things I've tried: if df[df['IDnumber'].str[0]] == '2': '''Do some stuff''' if df[df['IDnumber'].str.startswith('2')]