Delete Pandas DataFrame row if contains character [duplicate] - pandas

This question already has answers here:
how to search character plus using pandas.Series.str.contains
(1 answer)
Pandas Python Regex : error: nothing to repeat
(3 answers)
Pandas not counting rows properly
(3 answers)
Closed 4 years ago.
I'm trying to remove any row that contains a "?" in a particular column.
I have this line:
df[~df.C.str.contains("?")]
which doesn't work. I get the following error:
error: nothing to repeat at position 0
However the following does work
df[~df.C.str.contains("abc")]
Does anyone know what it is about ? that stops it running?

.str.contains() expects a regular expression by default; ? is treated as a metacharacter, and using it alone will raise re.error.* Pass regex=False to search for a literal "?" character:
df[~df.C.str.contains("?", regex=False)]
* See re.compile("?")

Related

Query for JSON value with unexpected character in path [duplicate]

This question already has an answer here:
How to allow special characters in JSON_VALUE
(1 answer)
Closed 11 months ago.
I'm working with JSON values in a database for the first time. I want to use JSON_VALUE or JSON_QUERY to return a value or section of the JSON, but whoever designed this went and used '-' in the keys, which is an illegal value. Research suggests I need to use FOR JSON to escape it, but I can't figure out how.
Attempt at the query:
select
xt.ID,
JSON_QUERY(xt.JSON_DB_VALUE, '$.CusomterQuery.Details.cust-names') as JSON_WITH_NAMES,
JSON_VALUE(xt.JSON_DB_VALUE, '$.CusomterQuery.Details.cust-names.first-name') as FIRST_NAME
from EXAMPLE_TABLE xt
Error received:
JSON path is not properly formatted. Unexpected character '-' is found at position xx.
Thanks
thanks to Zhorov's quick comment, this is the very simple solution - add quotation marks around the parts of the path with the illegal character.
select
xt.ID,
JSON_QUERY(xt.JSON_DB_VALUE, '$.CusomterQuery.Details."cust-names"') as JSON_WITH_NAMES,
JSON_VALUE(xt.JSON_DB_VALUE, '$.CusomterQuery.Details."cust-names"."first-name"') as FIRST_NAME
from EXAMPLE_TABLE xt

Parse error: syntax error, unexpected '–' (T_STRING) in PHP [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 2 years ago.
I am getting a Parse error: syntax error, unexpected '–' (T_STRING) in the following line:
$lbm = ((0.407 * $weightkg) + (0.267 * $heightcm) - 19.2) / 0.453592;
From what I see, I am using a subtraction sign and not a hyphen. Other than that, I don't know what could be wrong. Anyone know how to fix this?
Well, the character you pasted into the title is definitely an en-dash rather than a minus symbol(a) so PHP is rightly complaining about it.
The line in the main body of your question is a hyphen so either you've typed in in differently or that's not the line where the error is (PHP can sometimes be a bit iffy as to where it reports errors, so you may want to look on the few lines immediately around the one it reports the error to be on).
(a) Which is actually distinct from a hyphen, at least in typography, so you may want to beware of lunatic typographers coming around to beat you up for your transgressions :-)

Search by regular pattern in iOS [duplicate]

This question already has answers here:
What's the regular expression that matches a square bracket?
(10 answers)
Closed 3 years ago.
Trying to search bbcode-style tags with regular expression:
For example, I needed [user=1]John Dow[/user] with regular: [[user=[0-9]+].*?[/user]]
But couldn't receive needed result.
Remove the outer pair of brackets and escape the literal brackets (unlike the range-of-characters brackets)
let pattern = "\\[user=[0-9]+\\].*?\\[/user\\]"

SQL Server: How to call a string with apostrophe in name [duplicate]

This question already has an answer here:
T-SQL escape quote character
(1 answer)
Closed 8 years ago.
WHERE Variable = 'Lowe's';
But string is ending at Lowe because it recognizes the 's as end of String.
How to circumvent this?
Use two '
WHERE Variable = 'Lowe''s'
SQLFiddle demo
Although escaping ' with '' works, in case you are running this command from any application you should take a look at databinding and using SqlParameters - spares you a lot of headache, improves performance and security.

VB.NET function for uppercasing the first letter of each word [duplicate]

This question already has answers here:
How to uppercase the first character of each word using a regex in VB.NET?
(9 answers)
Closed 8 years ago.
I'm looking for do this in VB.NET,
hy how are you
to,
Hy How Are You
Anyone have any idea?
This following will do what you want without using regex (and is more readable than a regex solution):
Dim s As String = "some sentence that i want to capitalise"
Debug.WriteLine(Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s))
Output:
Some Sentence That I Want To Capitalise
And you can also do this (from the Microsoft.VisualBasic Namespace):
Debug.WriteLine(StrConv(s, VbStrConv.ProperCase))
You can do that using regular expressions. There are a useful class named Regex that will help you a lot. Please follow this link for more information.