Cypher don't reconnize gds function - cypher

i want to use gds.alpha.similarity.jaccard from https://neo4j.com/docs/graph-data-science/current/alpha-algorithms/jaccard/, but cypher send a error
Code:
RETURN gds.alpha.similarity.jaccard([1,2,3], [1,2,4,5]) AS similarity
Unknown function 'gds.alpha.similarity.jaccard' (line 1, column 8 (offset: 7))
"RETURN gds.alpha.similarity.jaccard([1,2,3], [1,2,4,5]) AS similarity"
How can use jaccard ?

Related

TypeError: '<' not supported between instances of 'int' and 'Timestamp'

I am trying to change the product name when the period between the expiry date and today is less than 6 months. When I try to add the color, the following error appears:
TypeError: '<' not supported between instances of 'int' and 'Timestamp'.
Validade is the column where the products expiry dates are in. How do I solve it?
epi1 = pd.read_excel('/content/timadatepandasepi.xlsx')
epi2 = epi1.dropna(subset=['Validade'])`
pd.DatetimeIndex(epi2['Validade'])
today = pd.to_datetime('today').normalize()
epi2['ate_vencer'] = (epi2['Validade'] - today) /np.timedelta64(1, 'M')
def add_color(x):
if 0 <x< epi2['ate_vencer']:
color='red'
return f'background = {color}'
epi2.style.applymap(add_color, subset=['Validade'])
Looking at your data, it seems that you're subtracting two dates and using this result inside your comparison. The problem is likely occurring because df['date1'] - today returns a pandas.Series with values of type pandas._libs.tslibs.timedeltas.Timedelta, and this type of object does not allow you to make comparisons with integers. Here's a possible solution:
epi2['ate_vencer'] = (epi2['Validade'] - today).dt.days
# Now you can compare values from `"ate_vencer"` with integers. For example:
def f(x): # Dummy function for demonstration purposes
return 0 < x < 10
epi2['ate_vencer'].apply(f) # This works
Example 1
Here's a similar error to yours, when subtracting dates and calling function f without .dt.days:
Example 2
Here's the same code but instead using .dt.days:

How to access an element in array vector using metaprogramming?

Here is a table t. The data form of column arr1 is array vector.
arr1=array(DOUBLE[], 0, 10).append!([2 3 4, 4 5 7, 7 9 10])
t = table(1..3 as id, arr1, rand(100, 3) as value)
I can use a SQL statement to query for the first element in column arr1, i.e., arr1[0].
select arr1[0] from t
Output:
arr1_at
2
4
7
Now I want to query using metaprogramming.
sql(select = sqlCol('arr1[0]') ,from =t).eval()
But an error was raised as follows:
Server response: 'Unrecognized column name arr1[0]
Try the following two lines:
sql(select=sqlColAlias(<arr1[0]>,"arr1_0"), from=t).eval()
sql(select=sqlColAlias(makeCall(at, sqlCol("arr1"), 0), "arr1_0"), from=t).eval()
Output:
arr1_0
2
4
7
The first line uses the metacode <arr1[0]>.
The second line uses function makeCall to call the at function to get the value at the 0-th position in column arr1 and thus obtain the new column arr1_0.

Confused Beginner learning Python

I am working on a problem in Python and don't understand the answer.
for number in range(1, 10):
if number % 2 == 0:
print(number)
The answer to this problem is 2,4,6,8
Can anyone explain this answer?
range is a function in python which generates a sequence of integers, for example:
r=range(3)
returns a iterable object range(0,3) which generates sequence of integers from 0 to 3-1(2),inorder for you to see the elements in it , you can loop through it:
for i in r:
print(i)
#prints number from 0 to 3-1
Or, wrap it in a list:
list(range(3)) //returns [0,1,2]
range can take 3 params as input start,end and optionally step.The parameters start and end are basically lower and upper bounds to the sequence.In the above example since we have given only one integer range considers start as 0 and end as 3. This function range(start,end,[step]) generates integers in the following manner: start,start+1....end-1 considering the above example 0,0+1...3-1
if you give both the start and the end params to the range, the function generates integers from start upto but not including end, Example:
for i in range(3,8):print(i) #prints numbers from 3 to 8-1
if you give the third parameter which is the step(which is usually 1 by default), then range adds that number to the sequence :
list(range(3,8)) or list(range(3,8,1)) # will return [3,4,5,6,7],sequence generation will be like:3,3+1,(3+1)+1...
list(range(3,8,2)) #returns [3,5,7];3,3+2,(3+2)+2....
So , coming to your question now :
for number in range(1, 10): if number % 2 == 0: print(number)
In the above code you are basically telling python to loop over the sequence of integeres between 1 to 9 and print the numbers which are divisible by 2,which prints 2,4,6,8.
Hope this helped you :)

What's the equivalent in Perl 6 to star expressions in Python?

In Python 3, suppose you run a course and decide at the end of the semester that you’re going to drop the first and last homework grades, and only average the rest of them:
def drop_first_last(grades):
first, *middle, last = grades
return avg(middle)
print drop_first_last([100,68,67,66,23]);
In Perl 6:
sub drop_first_last(#grades) {
my ($first, *#middle, $last) = #grades;
return avg(#middle);
}
say drop_first_last(100,68,67,66,23);
Leads to the error "Cannot put required parameter $last after variadic parameters".
So, what's the equivalent express in Perl 6 as star expressions in Python?
sub drop_first_last(Seq() \seq, $n = 1) { seq.skip($n).head(*-$n) };
say drop_first_last( 1..10 ); # (2 3 4 5 6 7 8 9)
say drop_first_last( 1..10, 2 ); # (3 4 5 6 7 8)
The way it works: convert whatever the first argument is to a Seq, then skip $n elements, and then keep all except the last $n elements.
Perl5:
sub drop_first_last { avg( #_[ 1 .. $#_-1 ] ) } #this
sub drop_first_last { shift;pop;avg#_ } #or this
Perl6:
sub drop_first_last { avg( #_[ 1 .. #_.end-1 ] ) }
Use a slice.
sub drop_first_last (#grades) {
return avg(#grades[1..*-2])
}
Workarounds such as have been shown in the rest of the answer are correct, but the short answer to your question is that there is no equivalent expression in Perl 6 to the * in Python.
This kind of arguments are called, in general, variadic, and *slurpy+ in Perl 6, because they slurp the rest of the arguments. And that's the key, the rest. There can be no argument declared after an slurpy argument in a subroutine's signature. This example below also uses a workaround:
sub avg( #grades ) {
return ([+] #grades) / +#grades;
}
sub drop_first_last($first, *#other-grades) {
return avg(#other-grades[0..*-1]);
}
my #grades = <10 4 8 9 10 8>;
say drop_first_last( |#grades );
but is first using the slurpy * in the signature to show how it works, and then, by calling it with |#grades, is flattening the array instead of binding it into an array argument. So the long answer is that there is actually an * or variadic symbol in signatures in Perl 6, and it works similarly to how it would do it in Python, but it can only be placed last in those signatures since it captures the rest of the elements of the expression.
In case the first and last values are needed for some other reason,
unflattened list structure inside slices maps across to the results
in most cases, so you can do this (you have to use a $ sigil on
$middle to prevent autoflattening):
my #grades = (1,2,3,4,5,6);
my ($first, $middle, $last) = #grades[0,(0^..^*-1),*-1];
$first.say; $middle.say; $last.say;
#1
#(2 3 4 5)
#6

"TypeError: bad operand type for unary ~: 'float'" not down to NA (not available)?

I'm trying to filter a pandas data frame. Following #jezrael's answer here I can use the following to count up the rows I will be removing:
mask= ((analytic_events['section']==2) &
~(analytic_events['identifier'].str[0].str.isdigit()))
print (mask.sum())
However when I run this on my data I get the following error:
TypeError Traceback (most recent call last)
in
1 mask= ((analytic_events['section']==2) &
----> 2 ~(analytic_events['identifier'].str[0].str.isdigit()))
3
4 print (mask.sum())
c:\program files\python37\lib\site-packages\pandas\core\generic.py in invert(self)
1454 def invert(self): 1455 try:
-> 1456 arr = operator.inv(com.values_from_object(self))
1457 return self.array_wrap(arr)
1458 except Exception:
TypeError: bad operand type for unary ~: 'float'
The accepted wisdom for that error, bad operand type for unary ~: 'float', is that the unary operator encountered a NA value (for example, see this answer)
The problem is that I do not have any such missing data. Here's my analysis. Running
analytic_events[analytic_events['section']==2]['identifier'].str[0].value_counts(dropna=False)
gives the results:
2 1207791
3 39289
1 533
. 56
Or running
analytic_events[analytic_events['section']==2]['identifier'].str[0].str.isdigit().value_counts(dropna=False)
gives the results
True 1247613
False 56
(Note that the amounts above sum to the total number of rows, i.e. there are none missing.)
Using the more direct method suggested in #jezrael's answer below
analytic_events[analytic_events['section']==2]['identifier'].isnull().sum()
analytic_events[analytic_events['section']==2]['identifier'].str[0].isnull().sum()
both produce the output zero. So there are no NA (not available) values.
Why am I getting the error
TypeError: bad operand type for unary ~: 'float'
from the code at the start of this post?
I believe you need filter by first condition and then again in filtered values:
m1 = analytic_events['section']==2
mask = ~analytic_events.loc[m1, 'identifier'].str[0].str.isdigit()
print (mask.sum())