where

For loop using np.where

余生长醉 提交于 2021-01-29 06:50:34
问题 I'm trying to create a new column in a dataframe that labels animals that are domesticated with a 1. I'm using a for loop, but for some reason, the loop only picks up the last item in the pets list. dog , cat , and gerbil should all be assigned a 1 under the domesticated column. Anyone have a fix for this or a better approach? df = pd.DataFrame( {'creature': ['dog', 'cat', 'gerbil', 'mouse', 'donkey'] }) pets = ['dog', 'cat', 'gerbil'] for pet in pets: df['domesticated'] = np.where(df[

Is it possible to call a function in my SELECT statement in php?

社会主义新天地 提交于 2021-01-28 12:00:42
问题 I have a database which holds different locations, each of which has its own longitude and latitude variable. I want to be able to use a distance function I made that returns the distance between two longitudes and latitudes in my WHERE statement. So I am looking for the distance between two points and it pass the WHERE statement if it is less than the radius I am searching. distance function: function distance($lat1, $lon1, $lat2, $lon2) { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1))

How to get the correct MethodInfo for “Where” extension method

纵饮孤独 提交于 2021-01-28 08:00:56
问题 I am trying to get return the correct "Where" extension method using reflection, in order to build a custom Expression. I have tried several ways but the closest I get, throws an exception: "An unhandled exception of type 'System.Reflection.AmbiguousMatchException' occurred in mscorlib.dll" I know this is because there are two Where methods defined in the Enumrable class - but how can I return the Where method which using only just a predicate of Func<T, bool>. What I have at the moment is:

Python Pandas Concat “WHERE” a Condition is met

本秂侑毒 提交于 2021-01-03 06:23:32
问题 How can I "concat" a specific column from many Python Pandas dataframes, WHERE another column in each of the many dataframes meets a certain condition (colloquially termed condition "X" here). In SQL this would be simple using JOIN clause with WHERE df2.Col2 = "X" and df3.Col2 = "X" and df4.col2 = "X"... etc (which can be run dynamically). In my case, I want to create a big dataframe with all the "Col1"s from each of the many dataframes, but only include the Col1 row values WHERE the

How to filter on pandas dataframe when column data type is a list

ぐ巨炮叔叔 提交于 2020-12-26 07:46:52
问题 I am having some trouble filtering a pandas dataframe on a column (let's call it column_1) whose data type is a list. Specifically, I want to return only rows such that column_1 and the intersection of another predetermined list are not empty. However, when I try to put the logic inside the arguments of the .where, function, I always get errors. Below are my attempts, with the errors returned. Attemping to test whether or not a single element is inside the list: table[element in table['column

Finding entries containing a substring in a numpy array?

笑着哭i 提交于 2020-12-02 06:12:51
问题 I tried to find entries in an Array containing a substring with np.where and an in condition: import numpy as np foo = "aa" bar = np.array(["aaa", "aab", "aca"]) np.where(foo in bar) this only returns an empty Array. Why is that so? And is there a good alternative solution? 回答1: We can use np.core.defchararray.find to find the position of foo string in each element of bar , which would return -1 if not found. Thus, it could be used to detect whether foo is present in each element or not by