conditional-statements

How to Group by Conditional aggregation of adjacent rows In PySpark

How to Group by Conditional aggregation of adjacent rows In PySpark Question: I am facing issue when doing conditional grouping in spark dataframe Below is complete example I have a dataframe, which has been sorted by user and by time activity location user 0 watch movie house A 1 sleep house A 2 cardio gym …

Total answers: 1

Conditional Shift in Pandas [calculate last win date]

Conditional Shift in Pandas [calculate last win date] Question: Help with conditional shifting in Pandas I have the following dataframe: rng = pd.date_range(‘2015-02-24′, periods=10, freq=’D’) win_list = [‘Won’, ‘Lost’, ‘Won’, ‘Won’, ‘Lost’, ‘Won’, ‘Lost’, ‘Lost’, ‘Lost’, ‘Won’] cust_list = [‘A’, ‘A’, ‘B’, ‘C’, ‘C’, ‘C’, ‘B’, ‘A’, ‘A’, ‘B’] output = [‘2015-02-24’, ‘2015-02-24’, ‘2015-02-26’, ‘2015-02-27’, …

Total answers: 1

I Have one for condition, and can't do if statement to count cell condition

I Have one for condition, and can't do if statement to count cell condition Question: I’m trying to do this condition to count how many times (cells) have values less than 300 seconds (5 minutes) but it returns me an error, the condition is about a DF below, that I pull from my csv: df …

Total answers: 1

Merge certain columns of a pandas dataframe with data from another dataframe by condition

Merge certain columns of a pandas dataframe with data from another dataframe by condition Question: I have the following challenge: I have two Pandas Dataframes with information about eg. chemical substances and related to some additional information. E.g. production region or country. For example, like this: data1 = { ‘Substance’ : [‘Substance1’, ‘Substance2’, ‘Substance1’, ‘Substance3’, …

Total answers: 1

Pandas dataframe duplicates – Python

Pandas dataframe duplicates – Python Question: I have a simplified dataframe like this: ID RecordingType Date Value 1 FEVR 2019-05-22 18:37:10 1.36 1 FEVR 2019-05-22 18:41:12 1.35 1 FEVR 2019-05-22 18:45:16 1.35 I am trying to run this code: df = df.sort_values(by=[‘ID’, ‘RecordingType’, ‘Date’], ascending=True).reset_index().drop(columns=["index"]) df["ToRemove"] = False dict_temp_df = df.to_dict("records") outputcolnames = {‘FEVR’:’Value’} for …

Total answers: 2

Trying to create a list of random times within specific date/time conditions

Trying to create a list of random times within specific date/time conditions Question: I am trying to modify this GitHub code for my own purposes in the title: import random from datetime import datetime, timedelta min_year=1900 max_year=datetime.now().year start = datetime(min_year, 1, 1, 00, 00, 00) years = max_year – min_year+1 end = start + timedelta(days=365 …

Total answers: 2

How to make python multiple conditions into a single statement

How to make python multiple conditions into a single statement Question: How to make the method below be returned in a single line? Prefer to the #Note ## remarks below. def falsify(leftover): #Note ## Your code here (replace with a single line) ### def falsify(leftover): false = [] for num in leftover: if 30 > …

Total answers: 2

Apply a condition to multiple columns to replace the

Apply a condition to multiple columns to replace the Question: I have a data frame with the below columns, some of the IGFRESAS columns have data in them, but I’ll only be replacing the data that doesn’t exist based on these conditions – see print screen I want to use the condition EV_EM == 0 …

Total answers: 1