Questions tagged [startswith]

Relates to the task of finding a subset of data at the beginning of a set of data. Usually refers to strings but could be other types of data. Please accompany with a language specific tag.

412 questions
13
votes
3 answers

sum values of columns starting with the same string in pandas dataframe

I have a dataframe with about 100 columns that looks like this: Id Economics-1 English-107 English-2 History-3 Economics-zz Economics-2 \ 0 56 1 1 0 1 0 0 1 11 0 …
Amanda
  • 835
  • 2
  • 9
  • 17
13
votes
7 answers

Retain elements in array if associative key starts with specific substring

If I have array like: array [ y => 35 x => 51 z => 35 c_3 => 4 c_1 => 54 c_6 => 53 c_9 => 52 ] I want to get array of: array [c_3=>4, c_1=>54, c_6=>53, c_9=>52] How can I filter out the elements…
user1435539
11
votes
1 answer

Dplyr select_ and starts_with on multiple values in a variable list

I am collecting data from differnt sensors in various locations, data output is something like: df<-data.frame(date=c(2011,2012,2013,2014,2015),"Sensor1 Temp"=c(15,18,15,14,19),"Sensor1 Pressure"=c(1001, 1000, 1002, 1004, 1000),"Sensor1a…
Bhav Shah
  • 167
  • 3
  • 10
8
votes
2 answers

select columns that do NOT start with a string using dplyr in R

I want to select columns from my tibble that end with the letter R AND do NOT start with a character string ("hc"). For instance, if I have a dataframe that looks like this: name hc_1 hc_2 hc_3r hc_4r lw_1r lw_2 lw_3r lw_4 Joe 1 2 …
J.Sabree
  • 2,280
  • 19
  • 48
7
votes
3 answers

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

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,…
McRae
  • 177
  • 1
  • 2
  • 12
7
votes
2 answers

String.StartsWith not Working when next character is the Prime Symbol (char)697

I am trying to use a string with the Prime symbol in it, but I am having some issues with the String.StartsWith method. Why is the following code throwing the exception? string text_1 = @"123456"; string text_2 = @"ʹABCDEF"; string fullText =…
Ben
  • 3,241
  • 4
  • 35
  • 49
6
votes
4 answers

Why is the T-SQL "LIKE" operator not evaluating this expression like I think it should?

I am attempting to error trap a T-SQL variable name by making sure that the value of the variable is prefixed with a bracket "[". Here's an example of how I am trying to do this: DECLARE @thing nvarchar(20) SET @thing = '[55555' IF(@thing NOT LIKE…
Jed
  • 10,649
  • 19
  • 81
  • 125
6
votes
3 answers

Why is this Lucene query a "contains" instead of a "startsWith"?

string q = "m"; Query query = new QueryParser("company", new StandardAnalyzer()).Parse(q+"*"); will result in query being a prefixQuery :company:a* Still I will get results like "Fleet Africa" where it is rather obvious that the A is not at the…
Boris Callens
  • 90,659
  • 85
  • 207
  • 305
6
votes
4 answers

How to filter a List using Java 8 stream and startwith array of values

I have 2 Lists, the one contains a list of numbers and the other a list of names. I have prefixed the names with a number from the first list, followed by an underscore. I want to filter the second list based on all the numbers found in the first…
Quentinb
  • 476
  • 1
  • 9
  • 30
6
votes
2 answers

Performance of String.StartsWith using StringComparison.OrdinalIgnoreCase

I ran into a strange performance "artifact" with String.StartsWith. It appears that String.StartsWith using OrdinalIgnoreCase is faster than using String.StartsWith without specifying a StringComparison. (2-4x faster) However, checking equality is…
MineR
  • 2,144
  • 12
  • 18
6
votes
1 answer

Cordova javascript error: has no method startsWith Android

i've got two devices one with Lollipop and one with Kitekat... the one with Lollipop does not report any error but when i try my application i obtain this error: 10-13 16:56:56.126: I/chromium(6322): [INFO:CONSOLE(99)] "Uncaught TypeError: Object…
Lorenzo
  • 673
  • 1
  • 11
  • 25
6
votes
3 answers

More efficient way to look up dictionary values whose keys start with same prefix

I have a dictionary whose keys come in sets that share the same prefix, like this: d = { "key1":"valA", "key123":"valB", "key1XY":"valC", "key2":"valD", "key2-22":"valE" } Given a query string, I need to look up all the values associated with…
I Z
  • 5,719
  • 19
  • 53
  • 100
6
votes
1 answer

Why this string ("ʿAbdul-Baha'"^^mso:text@de) doesn't start with "?

"\"ʿAbdul-Baha'\"^^mso:text@de".StartsWith("\"") // is false "\"Abdul-Baha'\"^^mso:text@de".StartsWith("\"") // is true (int)'ʿ' // is 703` is there anyone could tell me Why?
6
votes
2 answers

C# (String.StartsWith && !String.EndsWith && !String.Contains) using a List

I am a newbie in C#, and I am having problems. I have 2 List, 2 strings and a getCombinations(string) method that returns all combinations of a string as List; How do i validate if a subjectStrings element does not StartWith && !EndsWith &&…
5
votes
2 answers

How can I supply multiple conditions in spark startsWith() function?

I have a dataset with 5 Million records, I need to replace all the values in column using startsWith() supplying multiple or and conditions. This code works for a single condition: df2.withColumn("Deposits",…
SK Sayyad
  • 87
  • 9
1 2
3
27 28