filter

How to filter elements in a list that occur only once

How to filter elements in a list that occur only once Question: I need to filter and discard elements in a list that occur only once. I have the following list of integers as input. I need to make a new list that contains only elements that do not have singular appearances. item_list = [502, …

Total answers: 2

How to select user_id rows pandas

How to select user_id rows pandas Question: How can I calculate the first visited date and the last visited date before an order was placed by the user? USER ID TYPE DATE 1 Visited September 14, 2020 1 Visited October 4, 2020 1 Visited October 24, 2020 1 Ordered November 1, 2020 2 Visited September …

Total answers: 2

Pandas does not respect conversion to time type

Pandas does not respect conversion to time type Question: I have this dataframe: site date time 1 AA 2018-01-01 0100 2 AA 2018-01-01 0200 3 AA 2018-01-01 0300 4 AA 2018-01-01 0400 5 AA 2018-01-01 0500 6 AA 2018-01-01 0600 7 AA 2018-01-01 0700 8 AA 2018-01-01 0800 9 AA 2018-01-01 0900 df.dtypes >>> site …

Total answers: 1

Create column that orders ID by first Start Date

Create column that orders ID by first Start Date Question: Imagine I have the following dataframe: ID Start Date 1 1990-01-01 1 1990-01-01 1 1991-01-01 2 1991-01-01 2 1990-01-01 3 2002-01-01 3 2000-01-01 4 1991-01-01 What would be the best way to create a column named Order that, for each unique ID in the ID …

Total answers: 1

Confirm if LOV columns in a pandas dataframe complies with another mapping dataframe

Confirm if LOV columns in a pandas dataframe complies with another mapping dataframe Question: I have 2 dataframes, one of them of employee information by Country, and another one with a mapping of possible values for LOV columns per country (depending on the country, the column may or may not be an LOV and accept …

Total answers: 1

Picking/filtering element from pandas table where data is between column header values

Picking/filtering element from pandas table where data is between column header values Question: I have some 2D data that has boundaries (bins) like this: import numpy as npy # These are the boundaries of our wind speeds and directions speed_bins = npy.array([0.0, 0.5, 1.0, 2.0, 5.0, 10.0, 100.0]) dir_bins = npy.linspace(0,360,9) # Random LPF values …

Total answers: 1

Dataframe : replace value and values around based on condition

Dataframe : replace value and values around based on condition Question: I would like to create a filter to replace values in a dataframe column based on a condition and also the values around it. For exemple I would like to filter values and replace then with NaN if they are superior to 45 but …

Total answers: 2

How can I remove small pixel clusters from a transparent png using python

How can I remove small pixel clusters from a transparent png using python Question: I am trying to remove random pixel clusters noise from a transparent png using python. I have used eroding and then dilating like this import cv2 import numpy as np img = cv2.imread(‘test1.png’) blurred_img = cv2.medianBlur(img, 1) kernel = np.ones((2,2),np.uint8) erosion …

Total answers: 1

Filter Dataframe based on a list of codes, but each value of the column in question contains a list of many keys

Filter Dataframe based on a list of codes, but each value of the column in question contains a list of many keys Question: I have data (df1) that looks like this: INC_KEY AISPREDOT 180008916795 "[110402.0, 110602.0, 140651.0, 140694.0, 150402.0, 161002.0]" 180008916796 "[140655.0, 140694.0]" 180008916797 "[853151.0]" 180008916798 "[110402.0, 140652.0, 150202.0]" 180008916799 "[857300.0]" 180008916800 "[650634.0]" 180008916801 "[710402.0, …

Total answers: 2

Python – split one list to smaller lists conditionally

Python – split one list to smaller lists conditionally Question: Consider following list all_values = [ {"a": "first_type"}, {"a": "second_type"}, {"a": "second_type"}, {"a": "third_type"} ] I would like to build a dict: sorted_objs = { "first": [{"a": "first_type"}], "second": [{"a": "second_type"}, {"a": "second_type"}], "third": [{"a": "third_type"}] } What I do: for obj in all_values: if …

Total answers: 4