>>> marketing = User.search do |s|
>>> s.fulltext "Marketing"
>>> end
>>> marketing.total
1448
>>> sales = User.search do |s|
>>> s.fulltext "Sales"
>>> end
>>> sales.total
567
>>> marketing_and_sales = User.search do |s|
>>> s.fulltext "Marketing AND Sales"
>>> end
>>> marketing_and_sales.total
945
>>> marketing_or_sales = User.search do |s|
>>> s.fulltext "Marketing OR Sales"
>>> end
>>> marketing_or_sales.total
945
<Sunspot::Search:{:fq=>["type:User"], :q=>"Marketing AND Sales", :fl=>"* score", :qf=>"textfield1 textfield2 textfield3", :defType=>"dismax", :start=>0, :rows=>30}>
I want simple boolean queries to get working on sunspot-rails, solr
I tried many possibilities its not simply taking it.
The AND and NOT seems to be working as per the dismax configuration.
How can i make OR query working.
Thanks in advance.
I figured it out. You can specify the scope of the search criterias using any_of and all_of . though all_of doesnt work unless used inside any_of . here is the link http://sunspot.github.com/docs/Sunspot/DSL/Scope.html#all_of-instance_method
>>> marketing_or_sales = User.search do |s|
>>> s.any_of do
>>> s.fulltext "Marketing"
>>> s.fulltext "Sales"
>>> end
>>> end
>>> marketing_or_sales.total
945
Related
In Pandas we can drop cols/rows by .dropna(how = ..., axis = ...) but is there a way to get an array-like of True/False indicators for each col/row, which would indicate whether a col/row contains na according to how and axis arguments?
I.e. is there a way to convert .dropna(how = ..., axis = ...) to a method, which would instead of actual removal just tell us, which cols/rows would be removed if we called .dropna(...) with specific how and axis.
Thank you for your time!
You can use isna() to replicate the behaviour of dropna without actually removing data. To mimic the 'how' and 'axis' parameter, you can add any() or all() and set the axis accordingly.
Here is a simple example:
import pandas as pd
df = pd.DataFrame([[pd.NA, pd.NA, 1], [pd.NA, pd.NA, pd.NA]])
df.isna()
Output:
0 1 2
0 True True False
1 True True True
Eq. to dropna(how='any', axis=0)
df.isna().any(axis=0)
Output:
0 True
1 True
2 True
dtype: bool
Eq. to dropna(how='any', axis=1)
df.isna().any(axis=1)
Output:
0 True
1 True
dtype: bool
I have a dataframe I want to transpose, after doing this I need to call the columns but they are set as index. I have tried resetting the index to no avail
index False True
0 Scan_Periodicity_%_Changed 0.785003 0.214997
1 Assets_Scanned_%_Changed 0.542056 0.457944
I want the True and False columns to be regular columns but they are part of the index and I cannot call
df['True']
Expected Output:
False True
0 Scan_Periodicity_%_Changed 0.785003 0.214997
1 Assets_Scanned_%_Changed 0.542056 0.457944
and when i call True and False I want it to be a column not an index
df['True']
.214997
.457944
Try via reset_index(),set_index() and rename_axis() method:
out= (df.reset_index()
.set_index(['level_0','index'])
.rename_axis(index=[None,None]))
output of out:
False True
0 Scan_Periodicity_%_Changed 0.785003 0.214997
1 Assets_Scanned_%_Changed 0.542056 0.457944
Not sure what do you mean by "I want it to be a column not an index"
If you are looking for not having the 'index' value being displayed as a header you can do as
>>> import pandas as pd
>>>
>>> d = {
... 'index':['Scan_Periodicity_%_Changed','Assets_Scanned_%_Changed'],
... 'False':[0.78,0.54],
... 'True':[0.21,0.45]
... }
>>>
>>> df = pd.DataFrame(d)
>>>
>>> df = df.set_index('index')
>>>
>>> df.index.name = None
>>>
>>>
>>> df
False True
Scan_Periodicity_%_Changed 0.78 0.21
Assets_Scanned_%_Changed 0.54 0.45
I'm having the following error using NumPy:
>>> distance = 0.9014179933248182
>>> min_distance = np.array([0.71341723, 0.07322284])
>>> distance < min_distance
array([False, False])
which is right, but when I try:
>>> distance < min_distance.any()
True
which is obviously wrong, since there is no number in 'min_distance' smaller than 'distance'
What is going on here? I'm using NumPy on Google Colab, on version '1.17.3'.
Whilst numpy bugs are common, this is not one. Note that min_distance.any() returns a boolean result. So in this expression:
distance < min_distance.any()
you are comparing a float with a boolean, which unfortunately works, because of a comedy of errors:
bool is a subclass of int
True is equal to 1
floats are comparable with integers.
E.g.
>>> 0.9 < True
True
>>> 1.1 < True
False
What you wanted instead:
>>> (distance < min_distance).any()
False
try (distance < min_distance).any()
I seem to have a problem of argmax getting the right index for my array. It suppose to return a value 0 but I got a value 18. Here is an example:
>>> a = tf.constant([-0.00000000e+00, 1.31838050e-07, 7.86561927e-11,1.95077332e-09, 4.71118966e-09, 2.67971922e-10,3.62677839e-11 ,9.57063651e-10, 3.25077543e-09, 6.84045816e-08, 2.71129057e-08, 4.34358327e-10, 3.01831915e-09, 6.50069998e-09,1.40559550e-10, 4.57989238e-08, 1.42130885e-08, 9.68442881e-10, 8.28957923e-07,6.10620265e-09, 2.63989475e-09])
>>> a.eval()
array([ -0.00000000e+00, 1.31838050e-07, 7.86561927e-11,
1.95077332e-09, 4.71118966e-09, 2.67971922e-10,
3.62677839e-11, 9.57063651e-10, 3.25077543e-09,
6.84045816e-08, 2.71129057e-08, 4.34358327e-10,
3.01831915e-09, 6.50069998e-09, 1.40559550e-10,
4.57989238e-08, 1.42130885e-08, 9.68442881e-10,
8.28957923e-07, 6.10620265e-09, 2.63989475e-09], dtype=float32)
>>> b = tf.argmax(a,0)
>>> b.eval()
>>> 18
a[18]=8.2895792e-07 > a[0]=0
There is no problem, a[18] is the max value in your array, all your numbers are positive...
Is it allowable to subclass tables.Group?
The following code works fine
In [1]: import tables
In [2]: class Friendly_group(tables.Group):
...: def __repr__(self):
...: return 'hello!'
...:
In [3]: hf = tables.open_file('data', mode='w')
In [4]: fgroup = Friendly_group(hf.root, 'fgroup', new=True)
In [5]: hf
Out[5]:
File(filename=data, title='', mode='w', root_uep='/', filters=Filters(complevel=0, shuffle=False, fletcher32=False))
/ (RootGroup) ''
/fgroup (Friendly_group) ''
In [6]: hf.root.fgroup
Out[6]: hello!
But after reading back, that group stops being friendly
In [7]: hf.close()
In [8]: hf = tables.open_file('data', mode='r')
In [9]: hf
Out[9]:
File(filename=data, title='', mode='r', root_uep='/', filters=Filters(complevel=0, shuffle=False, fletcher32=False))
/ (RootGroup) ''
/fgroup (Group) ''
In [10]: hf.root.fgroup
Out[10]:
/fgroup (Group) ''
children := []
SO checker forces me to add some details to this post, but I really don't know how can I increase clearness of my question, so please, excuse me for this dummy piece of text.
Yes this is possible. The missing piece that you do not have that is needed for depersistence is to override the _c_classid class attribute. You probably want to look at other group subclasses that are present in tables/group.py. For instance, take the TransactionGroupG (stripped of some backwards compatibility features),
class TransactionGroupG(NotLoggedMixin, Group):
_c_classid = 'TRANSGROUP'
def _g_width_warning(self):
warnings.warn("""\
the number of transactions is exceeding the recommended maximum (%d);\
be ready to see PyTables asking for *lots* of memory and possibly slow I/O"""
% (self._v_max_group_width,), PerformanceWarning)
This is fairly minimal.