pivot

Pandas: Pivot to True/False, drop column

南笙酒味 提交于 2020-01-05 07:09:07
问题 I'm trying to create what I think is a simple pivot table but am having serious issues. There are two things I'm unable to do: Get rid of the "partner" column at the end. Set the values to either True or False if each company has that partner. Setup: df = pd.DataFrame({'company':['a','b','c','b'], 'partner':['x','x','y','y'], 'str':['just','some','random','words']}) Desired Output: company x y a True False b True True c False True I started with: df = df.pivot(values = 'partner', columns =

SQL Server : rows into columns

大城市里の小女人 提交于 2020-01-05 07:07:21
问题 I have three tables. I need to swith row values into columns. Table-1: [Approval_Type] App_ID Type_Ds 2 RMC2 1 RMC1 Table 2: [Project] Pro_id Summary 1 PROJECT1 2 PROJECT2 Table:3 [Prj_App] App_Id Pro_Id ExpDt ComDt 1 2 2010-06-05 2010-07-06 1 1 1999-05-05 1999-05-06 2 1 1900-01-01 1900-01-05 I want to display my result as Pro_Id RMC2 RMC2ExpeDt RMC2ComDt RMC1 RMC1ExpeDt RMC1ComDt 1 RMC2 1900-01-01 1900-01-05 RMC1 1999-05-05 1999-05-06 2 NULL NULL NULL RMC1 2010-06-05 2010-07-06 Below is my

How to convert columns into Rows

删除回忆录丶 提交于 2020-01-05 05:48:16
问题 I have a table data where the data will be shown like this : DatePeriod Good Fair Poor NotCategorised NotTested GoodPercentage FairPercentage PoorPercentage NotCategorisedPercentage NotTestedPercentage Feb-13 4 0 0 0 60 6.25 0 0 0 93.75 And for this one I have written query using UNPIVOT . Select DatePeriod,Legend FROM ( select DatePeriod,Good,Fair,Poor,NotCategorised,NotTested,GoodPercentage, FairPercentage,poorPercentage,NotCategorisedPercentage,NotTestedPercentage from #cte )P UNPIVOT

pandas: pivot table inside multilevel dataframe

人盡茶涼 提交于 2020-01-05 05:26:09
问题 I'm trying to pivot table, in order to transform some rows values in columns, so from this dataframe df_behave list date_time field value 1 0 2015-05-22 05:37:59 StudentID 129 1 2015-05-22 05:37:59 SchoolId 3 2 2015-05-22 05:37:59 GroupeId 45 2 3 2015-05-26 05:56:59 StudentID 129 4 2015-05-26 05:56:59 SchoolId 65 5 2015-05-26 05:56:59 GroupeId 13 6 2015-05-26 05:56:59 Reference 87 3 ...................... ...... ...... in order to achieve : list date_time StudentID SchoolId GroupId Reference

Accessing dynamically created stored procedure from LINQ

微笑、不失礼 提交于 2020-01-05 04:06:17
问题 I'm pivoting data in MS SQL stored procedure. Columns which are pivoted are dynamically created using stored procedure parameter (for exampe: "location1,location2,location3,") so number of columns which will be generated is not known. Output should look like (where locations are taken from stored procedure parameter): OrderTime | Location1 | Location2 | Location3 Any chance that this can be used in LINQ to SQL? When I dragged this procedure to dbml file it shows that this procedure returns

VBA to Create PivotTable, Type Mismatch? What Am I Doing Wrong?

瘦欲@ 提交于 2020-01-05 03:36:06
问题 Getting Type Mismatch on the line tabledestination:=("pivot!A3") I want to add a sheet and name it "Pivot" and create PivotTable on that sheet. Dim pt As PivotTable Dim Pcache As PivotCache Sheets.add.name = "Pivot" Sheets("DATA").Select Set Pcache = ActiveWorkbook.PivotCaches.Create(xlDatabase, Cells(1, 1).CurrentRegion) Set pt = ActiveSheet.PivotTables.Add(PivotCache, tabledestination:=("pivot!A3")) With pt PivotFields.Subtotals(1) = False .InGridDropZones = True .RowAxisLayout xlTabularRow

Stop the PivotControl allowing swipe

人盡茶涼 提交于 2020-01-04 13:42:35
问题 So I'm trying to make a "tabbed web browser" for Windows Phone 8. I can't seem to work out quite how I'm to do this bit. I've made all the tab control stuff using a PivotControl (it replaced TabControl in Windows 8 I believe). I can add & remove tabs dynamically, and I think that system is pretty good. Unfortunately, I can't work out how to stop the swipe gesture from changing tabs. I want the user to have to swipe only on the Pivot Controls header, not on the contents... I'm putting the

Excel VBA loop through Pivot Items

不羁的心 提交于 2020-01-04 09:19:34
问题 I want to loop through my pivot items and check if they exist in another table, see my Example Screenshot: So i want to loop through all the colors, checking if they exist in another table (e.g. in another sheet or so): Is there any way to do this so there would appear a Message Box that the color purple was not found in the list? Many thanks for your help! 回答1: You can use something like this: Sub ListMissingItems() Dim pt As PivotTable Dim pf As PivotField Dim pi As PivotItem Dim rngList As

How to convert many rows into Columns in SQL Server?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-04 09:14:12
问题 How would you convert a field that is stored as multiple rows into columns? I listed the code below as well. Below is an example of what is needed but it can really go up to 20 columns. Thanks! COL1 COL2 COL3 ---------------- TEST 30 NY TEST 30 CA TEST2 10 TN TEST2 10 TX I would like the output to be : COL1 COL2 COL3 COL4 ------------------------ TEST 30 NY CA TEST2 10 TN TX select * from ( select ID, Name, STORE, Group, Type, Date, State, row_number() over(partition by ID, state order by

How to rename items by assigning sequential number?

丶灬走出姿态 提交于 2020-01-04 03:59:06
问题 I have the following table: DECLARE @OperatorPrice TABLE ( ID INT NOT NULL, DealerId INT NULL, DealerName VARCHAR(50) NULL ) and sample data: INSERT INTO @OperatorPrice ( ID, DealerId, DealerName ) VALUES (226, 1, 'WestCarDealer') , (112, 1, 'WestCarDealer') , (266, 2, 'AO') , (112, 2, 'AO') , (93, 3, 'Best on the West') , (93, 3, 'Best on the West') What I want is to rename all dealers to 'Dealer1', 'Dealer2', 'Dealer3'. The number should be assigned in ascending order: AO should be renamed