where-clause

Is there a way to select all rows created today(current date), if that column has time format date and time?

Is there a way to select all rows created today(current date), if that column has time format date and time? Question: If I have a table that contains: table_id id_from_other_table date_time_when_this_row_was_added [(1, 200, ‘2023-01-06 08-11-21’)] [(2, 200, ‘2023-01-07 07-21-21’)] [(3, 200, ‘2023-01-07 08-10-10′)] Can I get all the rows that were created at today’s date …

Total answers: 1

How to select the given case statement as column

How to select the given case statement as column Question: I want to query the table after giving case statement/ %sql SELECT user_id, user_name, email, CASE WHEN user_name = ‘ruo’ THEN ‘No’ WHEN user_name = ‘ruoman’ THEN ‘Yes’ else ‘Other’ END AS New_Data FROM Pes %sql SELECT user_name from Pes where New_Data = ‘Yes’ –> …

Total answers: 1

Pandas: using where() method with another series?

Pandas: using where() method with another series? Question: I know what the where() method in pandas means. But in this case from the manual, I just cannot unterstand what they check with t = pd.Series([True, False]) Can someone maybe help? Here is the code: s = pd.Series(range(5)) t = pd.Series([True, False]) s.where(t, 99) 0 0 …

Total answers: 1

Python np.where not functioning consistently

Python np.where not functioning consistently Question: I am using np.where to test the value of a field(‘Security’) in the row (a) of a datatable as if the value is ‘Cash" I want to do something and if it is not then do something else. I am getting different behaviours depending on what I am putting …

Total answers: 1

Retrieving all numpy array indices where condition

Retrieving all numpy array indices where condition Question: Say I have a numpy array, a, of elements (which do not repeat) np.array([1,3,5,2,4]), I would like to retrieve the indices a contains [4,2]. Desired output: np.array([3,4]) as these are the indices the requested elements. So far, I’ve tried np.all(np.array([[1,2,3,4]]).transpose(), axis=1, where=lambda x: x in [1,2]) >>> …

Total answers: 1

Python: where clause with two conditions

Python: where clause with two conditions Question: I have a DataFrame as follows: data = [[99330,12,122], [1123,1230,1287], [123,101,812739], [1143,12301230,252]] df1 = pd.DataFrame(data, index=[‘2022-01-01’, ‘2022-01-02’, ‘2022-01-03’, ‘2022-01-04’], columns=[‘col_A’, ‘col_B’, ‘col_C’]) df1.index = pd.to_datetime(df1.index) for col in df1.columns: df1[col+’_mean’] = df1[col].rolling(1).mean().shift() df1[col+’_std’] = df1[col].rolling(1).std().shift() df1[col+’_upper’] = df1[col+’_mean’] + df1[col+’_std’] df1[col+’_lower’] = df1[col+’_mean’] – df1[col+’_std’] df1[col+’_outlier’] = np.where(df1[col]>df1[col+’_upper’] …

Total answers: 1

Combine unique IDs and create an extra ID column

Combine unique IDs and create an extra ID column Question: I have a dataframe with employee names, each row representing their contract information, the type of employee of their contract, the contract ID and which contract is the primary one (if the person has 1 contract, it is always marked as "Yes", if they have …

Total answers: 1

Idiomatic Rust index filtering (numpy style)

Idiomatic Rust index filtering (numpy style) Question: A common idiom that I use in python for initializing arrays is arr = np.zeros(10) x = np.linspace(-5,5,10) arr[np.abs(x)<2] = 1. That is, conditionally changing elements of an array using a "view". Is there an idiomatic way of doing this (also with a vector or other collection) in …

Total answers: 2

SQL: Loop through items in dictionary

SQL: Loop through items in dictionary Question: I have created a dictionary as follows: dict = { ‘NASDAQ’: {‘AMZN%’, ‘AAPL%’, ‘ABNB%’}, ‘TSX’: {‘SHOP%’, ‘L%’, ‘RY%’, ‘XIF%’}} I want to write a for loop within a query to fetch data from a table TICKER_TABLE with a column called TICKER which contains the dict values. The query …

Total answers: 2

mask and apply numpy where function to a vector in c++

mask and apply numpy where function to a vector in c++ Question: I’m using C++ and want to combine the masking of a vector and the search for the indexes where a condition is verified, similarly to the numpy where function. Here’s an example: std::vector<int> id = {61, 66, 68, 80} std::vector<int> val = {0, …

Total answers: 2