I have a dataframe which consist of order_date,order_time for multiple restaurant. I want to create a new column which would calculate the queue based on order date and time.
I have tried using diff() on order time along with group by on order_date and restaurant_id but it didnt worked.
Expected output : a new column 'time_diff' which would contain difference between consecutive orders for same restaurant and on same date.
Related
I have a dataframe of customer purchases containing customer email addresses, purchase ID, purchase date, first event date, etc.
I am trying to create a new Dataframe that will consist of three columns namely: email address, purchases_before_event and purchases_after_event.
My goal is to determine the impact of the first event attended by the customer on the buying behaviour. The first event date of the original dataframe contains the date of the first company event attended by the customers.
I have tried to create an empty dictionary, then iterate through the rows of the original dataset setting the condition that if the purchase date is greater than the event date, then the dictionary is populated with the email as key, then "before_event" and "after_event" is inserted or incremented according as the case maybe. However the error message in the screenshot below got returned.
I have some data in excel that are formulated as so:
I need the records with identical features to merge to one record with the oldest active date to the newest active date and the ones with changes to remain split. Basically, if there are no changes there should be one record with new active dates and if there is one change 2 records, 2 changes-3 records as so:
I'd really appreciate the help.
I tried ordering the data by id and date and applying an if statement where if there the id above or below are equal AND any of the features are not equal than return the same date and if they are equal than return the oldest and newest date for begin and end date respectively for that ID number so that they would have identical date ranges and then deleting the duplicates but resulted in the records and the records that were not sorted in a particular order not merging since it only compared the records to the ones above or below it.
I'm using the following AQL to track unique visitors by month and year. Each hit contains a datetime stamp, _date, and a user name, user.
FOR hit IN PageHits
COLLECT month = DATE_MONTH(hit._date),year=DATE_YEAR(hit._date) INTO user=hit.user
SORT year,month
RETURN {month,year,uniqueVisitors:LENGTH(UNIQUE(user))}
The query calculates the correct answer but it strikes me as inefficient because the variable user contains many duplicates. The final LENGTH/UNIQUE removes these and returns the number of unique visitors.
I looked at AGGREGATE but all of the operations are statistical.
So, is there any way to add only distinct/unique values into the group variable user?
I need some suggestion to generate a continuous dates in between a specified selected date range in Cognos. I can create a separate Data item for this but I don't know what to do after that. Looking for a quick help
You need to get your list from a Calendar table which joins to your query in framework, or create a seperate Query Subject that pulls in the date list from a Calendar table or custom SQL. For more info on generating a range of dates using SQL see this: Generate a range of dates using SQL
Once you have a query subject with a date field that contains 1 record per date you want, create a dummy field to use to join it to your main query. A simple data item named 'join1' with the value '1' will work. Create the same field in your main query. Join the two Query Subjects together on the 'join1' field. This is going to result in your data getting multiplied out into the date range. IE. If you have a main query that lists 1 record per employee, the result after the join will be 1 record per employee per date in your date range.
I have a list of all orders placed in a time range and I am trying to calculate the difference between each customer's first and second order. I have a list of unique customer IDs on another tab and I already have the first order date for each. I need a way to grab the date of the second order, corresponding to each customer ID.
In the sample data below, the correct output of this formula for customer ID "153950" would be "5/11/17 8:41".
Use AGGREGATE()
=AGGREGATE(15,6,Sheet1!C1:C4/(Sheet1!A1:A4 = 153950),2)
The ,2 is grabbing the second smallest date.