aggregate-functions

How can I keep track of total transaction amount sent from an account each last 6 month?

独自空忆成欢 提交于 2021-02-04 05:18:59
问题 This is my transaction data data id from to date amount <int> <fctr> <fctr> <date> <dbl> 19521 6644 6934 2005-01-01 700.0 19524 6753 8456 2005-01-01 600.0 19523 9242 9333 2005-01-01 1000.0 … … … … … 1055597 9866 9736 2010-12-31 278.9 1053519 9868 8644 2010-12-31 242.8 1052790 9869 8399 2010-12-31 372.2 Now for each distinct account in from column, I want to keep track of how much transaction amount they sent over last 6 month at the time the transaction was made and so I want to do it

How can I keep track of total transaction amount sent from an account each last 6 month?

為{幸葍}努か 提交于 2021-02-04 05:13:59
问题 This is my transaction data data id from to date amount <int> <fctr> <fctr> <date> <dbl> 19521 6644 6934 2005-01-01 700.0 19524 6753 8456 2005-01-01 600.0 19523 9242 9333 2005-01-01 1000.0 … … … … … 1055597 9866 9736 2010-12-31 278.9 1053519 9868 8644 2010-12-31 242.8 1052790 9869 8399 2010-12-31 372.2 Now for each distinct account in from column, I want to keep track of how much transaction amount they sent over last 6 month at the time the transaction was made and so I want to do it

SQL Getting sum of all rows with Inner join and group by

廉价感情. 提交于 2021-01-29 09:24:10
问题 I am trying to get the sum of rows of the same DueDate . I'm joing 2 tables to populate other fields. However, I'm having difficulty aggregating the values on Amount column so that I can end up with one row for a specific DueDate The other columns all have the same value except the Amount and DueDate . Below is my query SELECT T2.Company, T2.Code T2.DueDate, SUM(T2.Amount) FROM TBL2 T2 LEFT JOIN TBL1 T1 ON T2.Company = T1.Company AND T2.Code IN ( 0, 1, 2, 3, 4, 5, 6, 7, 8 ) GROUP BY T1

How to get arrays from a normalised table that stores array elements by index?

一曲冷凌霜 提交于 2021-01-29 08:26:19
问题 I have a table storing array elements by the array they belong to and their index in the array. It seemed smart because the arrays were expected to be sparse, and have their elements updated individually. Let's say this is the table: CREATE TABLE values ( pk TEXT, i INTEGER, value REAL, PRIMARY KEY (pk, i) ); pk | i | value ----+---+------- A | 0 | 17.5 A | 1 | 32.7 A | 3 | 5.3 B | 1 | 13.5 B | 2 | 4.8 B | 4 | 89.1 Now I would like to get these as real arrays, i.e. {17.5, 32.7, NULL, 53} for

PostgreSQL: Identifying return visitors based on date - joins or window functions?

纵然是瞬间 提交于 2021-01-28 05:11:46
问题 I am looking to identify return visitors to a website within a 7 day window. A data sample and attempt at solving are included below: visitor_id(integer) session_id(integer) event_sequence(integer) d_date(date) Sample raw data: +-----------+-------------+----------------+-------------+ | visitor_id| session_id | event_sequence | d_date | +-----------+-------------+----------------+-------------+ | 1 | 1 | 1 | 2017-01-01 | | 1 | 1 | 2 | 2017-01-01 | | 1 | 1 | 3 | 2017-01-01 | | 1 | 2 | 1 |

UPDATE with jsonb_set() only affects one object in nested array

≯℡__Kan透↙ 提交于 2021-01-28 04:56:31
问题 Trying to update all elements of a nested array in a jsonb column, but only one element is updated. My query: update table_ set value_ = jsonb_set(value_,cte.json_path,cte.namevalue,false) FROM ( select vals2->'ao'->'sc'->'name' as namevalue, ('{iProps,'||index1-1||',value,rules,'||index2-1||',ao,sc}')::text[] as json_path from table_, jsonb_array_elements(value_->'iProps') with ordinality arr1(vals1,index1), jsonb_array_elements(vals1->'value'->'rules') with ordinality arr2(vals2,index2) )

how to aggregate only the numerical columns in a mixed dtypes dataframe

爷,独闯天下 提交于 2021-01-27 18:43:45
问题 I have a mixed pd.DataFrame : import pandas as pd import numpy as np df = pd.DataFrame({ 'A' : 1., 'B' : pd.Timestamp('20130102'), 'C' : pd.Timestamp('20180101'), 'D' : np.random.rand(10), 'F' : 'foo' }) df Out[12]: A B C D F 0 1.0 2013-01-02 2018-01-01 0.592533 foo 1 1.0 2013-01-02 2018-01-01 0.819248 foo 2 1.0 2013-01-02 2018-01-01 0.298035 foo 3 1.0 2013-01-02 2018-01-01 0.330128 foo 4 1.0 2013-01-02 2018-01-01 0.371705 foo 5 1.0 2013-01-02 2018-01-01 0.541246 foo 6 1.0 2013-01-02 2018-01

Aggregate groups in Python Pandas and spit out percentage from a certain count

核能气质少年 提交于 2021-01-27 06:32:32
问题 I am trying to figure out how to aggregate groups in Pandas data frame by creating a percentage and summation on the new columns. For example, in the following data frame, I have columns A, B, C, and D. I would like to aggregate by groups in A, and C should be a percent of (frequency of '1' divided by frequency of non-missing value), and D should be a summation of non-missing values. For example, for 'foo' group, the resulting data frame should be A B C D foo 1.333 4 I am able to do some of

Aggregate groups in Python Pandas and spit out percentage from a certain count

坚强是说给别人听的谎言 提交于 2021-01-27 06:31:48
问题 I am trying to figure out how to aggregate groups in Pandas data frame by creating a percentage and summation on the new columns. For example, in the following data frame, I have columns A, B, C, and D. I would like to aggregate by groups in A, and C should be a percent of (frequency of '1' divided by frequency of non-missing value), and D should be a summation of non-missing values. For example, for 'foo' group, the resulting data frame should be A B C D foo 1.333 4 I am able to do some of

R: convert dates from daily to weekly and plotting them

五迷三道 提交于 2021-01-20 12:26:46
问题 I am trying to learn how to deal with time series data. I created some fake daily data, tried to aggregate it by week and then plot it: set.seed(123) library(xts) library(ggplot2) date_decision_made = seq(as.Date("2014/1/1"), as.Date("2016/1/1"),by="day") date_decision_made <- format(as.Date(date_decision_made), "%Y/%m/%d") property_damages_in_dollars <- rnorm(731,100,10) final_data <- data.frame(date_decision_made, property_damages_in_dollars) y.mon<-aggregate(property_damages_in_dollars