pivot

How to UnPivot COLUMNS into ROWS in AWS Glue / Py Spark script

心已入冬 提交于 2021-02-11 15:05:00
问题 I have a large nested json document for each year (say 2018, 2017), which has aggregated data by each month (Jan-Dec) and each day (1-31). { "2018" : { "Jan": { "1": { "u": 1, "n": 2 } "2": { "u": 4, "n": 7 } }, "Feb": { "1": { "u": 3, "n": 2 }, "4": { "u": 4, "n": 5 } } } } I have used AWS Glue Relationalize.apply function to convert above hierarchal data into flat structure: dfc = Relationalize.apply(frame = datasource0, staging_path = my_temp_bucket, name = my_ref_relationalize_table,

Conditional aggregation, filter in laravel

眉间皱痕 提交于 2021-02-11 13:23:57
问题 This is my second question based after the solution of Rows to columns based on date/time in Postgresql The table is in the upper link :) Here is my model: namespace App; use Illuminate\Database\Eloquent\Model; class StambMeasCanal extends Model { protected $connection = 'stamb'; protected $table = 'meas_kanal'; protected $fillable = ['fullname','formattedvalue','recordtime','qualitydesc','statedesc','id']; } Part of my controller: function getdata(Request $request) { $start_date = date('d-m

how to make a new table from an existing table and add new column in spreadsheet

不打扰是莪最后的温柔 提交于 2021-02-11 08:43:00
问题 I want to Ask about spreadsheet or google-sheets formula. I have a data that looks like this: A B C D ------------------------------------------------ 1 | UserId fruitType media PriceStatus 2 | 3 Apple Bag Paid 3 | 7 Banana Bag Paid 4 | 7 Apple Bag Paid 5 | 43 Banana Bag Paid 6 | 43 Apple Bag FREE 7 | 43 Apple Cart Credit Note: My data only consist of 2 type of fruit : Apple and banana 2 type of media : Bag and Cart 3 Type of PriceStatus : Paid , Credit , & Free As you can see the column is

dynamic pivot issue in sql server 2012

做~自己de王妃 提交于 2021-02-11 06:21:49
问题 I'm trying to implement a dynamic pivoting in SQL to represent my results given below ID Charge Message Amt Of Billing 4563 WEB FEE 9.75 4563 MONTHLY FEE 6 4563 CLUB FEE 9.95 4648 MONTHLY FEE 6 4648 ACCOUNT FEE 5 4648 CLUB FEE 9.95 4648 WEB FEE 9.75 4650 MONTHLY FEE 6 4650 WEB FEE 9.75 4650 CLUB FEE 9.95 into a desired representation like this. ID ACCOUNT FEE MONTHLY FEE CLUB FEE WEB FEE 4563 6 9.95 9.75 4648 5 6 9.95 9.75 4650 6 9.95 9.75 Your help is highly appreciated. 回答1: For a dynamic

dynamic pivot issue in sql server 2012

◇◆丶佛笑我妖孽 提交于 2021-02-11 06:21:11
问题 I'm trying to implement a dynamic pivoting in SQL to represent my results given below ID Charge Message Amt Of Billing 4563 WEB FEE 9.75 4563 MONTHLY FEE 6 4563 CLUB FEE 9.95 4648 MONTHLY FEE 6 4648 ACCOUNT FEE 5 4648 CLUB FEE 9.95 4648 WEB FEE 9.75 4650 MONTHLY FEE 6 4650 WEB FEE 9.75 4650 CLUB FEE 9.95 into a desired representation like this. ID ACCOUNT FEE MONTHLY FEE CLUB FEE WEB FEE 4563 6 9.95 9.75 4648 5 6 9.95 9.75 4650 6 9.95 9.75 Your help is highly appreciated. 回答1: For a dynamic

postgres crosstab, ERROR: The provided SQL must return 3 columns

时间秒杀一切 提交于 2021-02-10 20:52:43
问题 Hello I have created a view, but want to pivot it. OUTPUT before pivoting: tag1 | qmonth1 | qmonth2 | sum1 --------+-----------+-----------+-------- name1 | 18-05 | MAY | -166 name2 | 18-05 | MAY | -86 name3 | 18-05 | MAY | 35 name1 | 18-06 | JUN | -102 name2 | 18-06 | JUN | -32 name3 | 18-06 | JUN | -75 name1 | 18-09 | AVG | -135 name2 | 18-09 | AVG | -52 name3 | 18-09 | AVG | -17 expected output: qmonth2 | name1 | name2 | name3 --------+-------+-------+------- MAY | -166 | -86 | 35 JUN |

postgres crosstab, ERROR: The provided SQL must return 3 columns

北城以北 提交于 2021-02-10 20:51:42
问题 Hello I have created a view, but want to pivot it. OUTPUT before pivoting: tag1 | qmonth1 | qmonth2 | sum1 --------+-----------+-----------+-------- name1 | 18-05 | MAY | -166 name2 | 18-05 | MAY | -86 name3 | 18-05 | MAY | 35 name1 | 18-06 | JUN | -102 name2 | 18-06 | JUN | -32 name3 | 18-06 | JUN | -75 name1 | 18-09 | AVG | -135 name2 | 18-09 | AVG | -52 name3 | 18-09 | AVG | -17 expected output: qmonth2 | name1 | name2 | name3 --------+-------+-------+------- MAY | -166 | -86 | 35 JUN |

postgres crosstab, ERROR: The provided SQL must return 3 columns

让人想犯罪 __ 提交于 2021-02-10 20:50:42
问题 Hello I have created a view, but want to pivot it. OUTPUT before pivoting: tag1 | qmonth1 | qmonth2 | sum1 --------+-----------+-----------+-------- name1 | 18-05 | MAY | -166 name2 | 18-05 | MAY | -86 name3 | 18-05 | MAY | 35 name1 | 18-06 | JUN | -102 name2 | 18-06 | JUN | -32 name3 | 18-06 | JUN | -75 name1 | 18-09 | AVG | -135 name2 | 18-09 | AVG | -52 name3 | 18-09 | AVG | -17 expected output: qmonth2 | name1 | name2 | name3 --------+-------+-------+------- MAY | -166 | -86 | 35 JUN |

select first in and last out time - different date - from data finger

允我心安 提交于 2021-02-10 17:45:47
问题 Here is my data finger table, [dbo].[tFPLog] CardID Date Time TransactionCode 100 2020-09-01 08:00 IN 100 2020-09-01 17:00 OUT 100 2020-09-01 17:10 OUT 200 2020-09-01 16:00 IN 200 2020-09-02 02:00 OUT 200 2020-09-02 02:15 OUT 100 2020-09-02 07:00 IN 100 2020-09-02 16:00 OUT 200 2020-09-02 09:55 IN 200 2020-09-02 10:00 IN 200 2020-09-02 21:00 OUT Conditions Assume Employees will be IN and OUT in same day/next day. Assume There will be multiple IN and OUT for same day/next day for employees. So

How to reshape dataframe with wide_to_long or pivot?

北城余情 提交于 2021-02-10 11:55:33
问题 This should be fairly simple but have not been able to wrap my brain around it. I am trying to convert df1 to df2, where df1 and df2 are pandas dataframes df1 = pd.DataFrame({'site': ['1', '2'], 'sat_open': ['0900', '0900'], 'sat_close': ['1900','1900'], 'sun_open': ['1000', '1000'], 'sun_close': ['1800', '1800'], 'mon_open': ['0900', '0900'], 'mon_close': ['2100', '2100'] }) df2 = pd.DataFrame({'store': ['1', '1', '1', '2', '2','2'], 'day': ['sat', 'sun', 'mon','sat', 'sun', 'mon'], 'open':