This question already has answers here:
How to filter Pandas dataframe using 'in' and 'not in' like in SQL
(11 answers)
Closed 3 years ago.
I'm trying to remove rows from a dataframe if a particular column value does not appear in a previously defined dictionary
dff= dff[dff['network'] in net_dic]
Each value of 'network' is a string. and net_dic looks like this:
{ 'abc' : 1
'def' : 2
.
.
.}
It errors:
TypeError: 'Series' objects are mutable, thus they cannot be hashed
Ah this works:
dff= dff[dff['network'].isin(net_dic.keys())]
Related
This question already has answers here:
How to add a constant column in a Spark DataFrame?
(3 answers)
Closed 10 days ago.
I am trying to query a dataframe and add a column with a set value but I'm not sure how to get it to work. I know how it works in SQL but I could use help converting it to pyspark.
PL/SQL Example:
SELECT 1 AS column1
,2 AS column2
FROM dual;
pyspark:
empDF.select("name", col("").alias("nullColumn")).display()
Please have a look at the withColumn() function. Can be used in conjunction with lit()
https://spark.apache.org/docs/3.1.3/api/python/reference/api/pyspark.sql.DataFrame.withColumn.html
A new column can be added to an existing dataframe using this option.
Sample Example:
df.withColumn("Country", lit("USA")).show()
df.withColumn("Country", lit("USA")) \
.withColumn("anotherColumn",lit("anotherValue")) \
.show()
Example Source: Google led to https://azurelib.com/withcolumn-usage-in-databricks-with-examples/
Hope it helps...
This question already has answers here:
Postgres error updating column data
(2 answers)
PostgreSQL "column "foo" does not exist" where foo is the value
(1 answer)
postgres column "X" does not exist
(1 answer)
Simple Postgresql Statement - column name does not exists
(2 answers)
Error: Column does not exist in postgresql for update [duplicate]
(1 answer)
Closed 5 months ago.
I would like to add columns by following window function.
select goods_code,event_code ,DENSE_RANK() Over (
Order By case when goods_code = "aaaa" then 1 end,
case when event_code = "a" then 1 end)
from atai.pricing_pattern
but it returned following error.
ERROR: column "aaaa" does not exist
LINE 1: ...ENSE_RANK() Over (Order By case when goods_code = "aaaa" the...
^
What is the root cause of this? if someone has opinion,will you please let me know
Thanks
This question already has answers here:
How to execute an IN lookup in SQL using Golang?
(9 answers)
How to pass variable ids to statement.Query() in golang?
(1 answer)
Closed 10 months ago.
The community reviewed whether to reopen this question 10 months ago and left it closed:
Original close reason(s) were not resolved
I have a sql query like
SELECT SOME_FIELD FROM SOME_TABLE WHERE ID_FIELD IN ("abc", "def", "...", ...)
And an array that i need to pass as a parameter
p := []interface{"abc", "def", "blah", "foo"}
I prepare the statement:
stmt, err := conn.Prepare("SELECT SOME_FIELD FROM SOME_TABLE WHERE ID_FIELD IN (:1)")
rows, err := stmt.Query(p) // <- this complains that I pass an array as a value
I know that i can convert that array into a comma separated string of quoted values, but i wonder if there is a better way of passing an array of values as a parameter to a query
For moderators who closed my question previously: There is a similar question How to pass variable ids to statement.Query() in golang? but it is not the same. The answer to that question suggests unpacking the array when passing to the Query, like stmt.Query(...p) - but this will not work in my case as this will be treated as a number of parameters instead of one array parameter
This question already has answers here:
PostgreSQL substring get string between brackets
(2 answers)
Closed 1 year ago.
I have the following details column, with varying parameters. How can I get only joblib values? "The Place of joblib is not always the same, so I may bot be able to use substring count"
date:01/12/2014--**--joblib:[snbsd]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2014--**--joblib:[jinxthin]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2014--**--joblib:[snbserv]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2016--**--joblib:[sql12server]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2015--**--joblib:[stfmbinserx]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2011--**--joblib:[ftplikes]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
Desired result:
snbsd
jinxthin
snbserv
sql12server
stfmbinserx
ftplikes
Here You go:
substring(substring(var1, position('joblib:' in var1)+8), 1, position(']' in substring(var1, position('joblib:' in var1)+8))-1)
replace var1 with column name containing Your string
With below You can try it out directly on PostgreSQL:
WITH myconstants (var1) as (
values ('date:01/12/2014--**--joblib:[snbsd]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto')
)
SELECT substring(substring(var1, position('joblib:' in var1)+8), 1, position(']' in substring(var1, position('joblib:' in var1)+8))-1)
FROM myconstants
This question already has answers here:
Equals(=) vs. LIKE
(16 answers)
WHERE clause on SQL Server "Text" data type
(7 answers)
Closed 7 years ago.
what is the differences between = to like ?
thanks for help :)
by the way if it's help , the error i get is: the data types text and varchar are incompatible in the equal to operator [msg 402]
1:
Like
The LIKE operator is used to search for a specified pattern in a column.
Where
The WHERE clause is used to extract only those records that fulfill a specified criterion.
In your case the first query do not work is because no records match the criteria you are searching.