pivot-table

Pivot Table-like Output in R?

為{幸葍}努か 提交于 2021-02-05 17:20:41
问题 I am writing a report that requires the generation of a number of pivot tables in Excel. I would like to think there is a way to do this in R so that I can avoid Excel. I would like output like the screenshot below (teacher names redacted). As far as I can tell, I could use the reshape package to calculate the aggregate values, but I'd need to do that a number of times and somehow get all of the data in the correct order. At that point, I should just be doing it in Excel. Does anyone have any

Python pandas pivot_table margins keyError

余生颓废 提交于 2021-01-29 13:53:54
问题 Consider the following dataframe: test = pd.DataFrame({'A': [datetime.datetime.now(), datetime.datetime.now()], 'B': [1, 2]}) If I use pivot_table like below then everything is fine: test.pivot_table(index = 'A', aggfunc = {'B': 'mean'}, margins = True) However, if I do the following, I can't set margins = True (throws the error KeyError: 'A' ): test.pivot_table(index = test['A'], aggfunc = {'B': 'mean'}, margins = True) I am really confused. Let's say I need do something like below AND need

Filtering table to create another table in Excel

非 Y 不嫁゛ 提交于 2021-01-29 10:17:13
问题 I need to receive values from a table where a condition is met. For example I have names and I need to take all values from a table where the name appears. For example the table consists of date, name, expenditures: Date Name Expenditures 2019-01-28 Sara 2.45 2019-04-26 John 32.67 2019-05-07 Peter 55.88 2019-06-14 Sara 62.09 2019-07-03 Sara 12.94 2019-09-30 Peter 5.64 I need to receive all expenditures which has been made by Sara and the Date days when it was done. The result should be the

Add calculated column in pivot table based on other columns in the same pivot table

别等时光非礼了梦想. 提交于 2021-01-29 09:30:00
问题 I have a pivot table that calculates the count of pallets of each type of product and the sum of the age I want to add a calculated field/column with the average age of each product R/Q in this case. But when I try and add calculated field I only get options from the original table, meaning I can't get the count and sum of the apples. Can this be done? EDIT: I want this to be part of the pivot table since I want to be able to sort on this calculated value. If I add this value "outside" I can

Pandas pivot table subtotals with multi-index

我的梦境 提交于 2021-01-28 16:50:32
问题 I'm trying to create a simple pivot table with subtotals, excel-style, however I can't find a method using Pandas. I've tried the solution Wes suggested in another subtotal-related question, however that doesn't give the expected results. Below the steps to reproduce it: Create the sample data: sample_data = {'customer': ['A', 'A', 'A', 'B', 'B', 'B', 'A', 'A', 'A', 'B', 'B', 'B'], 'product': ['astro','ball','car','astro','ball', 'car', 'astro', 'ball', 'car','astro','ball','car'], 'week': [1

Pandas pivot table subtotals with multi-index

扶醉桌前 提交于 2021-01-28 16:47:48
问题 I'm trying to create a simple pivot table with subtotals, excel-style, however I can't find a method using Pandas. I've tried the solution Wes suggested in another subtotal-related question, however that doesn't give the expected results. Below the steps to reproduce it: Create the sample data: sample_data = {'customer': ['A', 'A', 'A', 'B', 'B', 'B', 'A', 'A', 'A', 'B', 'B', 'B'], 'product': ['astro','ball','car','astro','ball', 'car', 'astro', 'ball', 'car','astro','ball','car'], 'week': [1

Pandas pivot table subtotals with multi-index

房东的猫 提交于 2021-01-28 16:47:35
问题 I'm trying to create a simple pivot table with subtotals, excel-style, however I can't find a method using Pandas. I've tried the solution Wes suggested in another subtotal-related question, however that doesn't give the expected results. Below the steps to reproduce it: Create the sample data: sample_data = {'customer': ['A', 'A', 'A', 'B', 'B', 'B', 'A', 'A', 'A', 'B', 'B', 'B'], 'product': ['astro','ball','car','astro','ball', 'car', 'astro', 'ball', 'car','astro','ball','car'], 'week': [1

getPivotCacheDefinition return null value when Refresh Pivot Table with Apache POI

﹥>﹥吖頭↗ 提交于 2021-01-28 10:48:33
问题 I want to refresh pivot table after enter data to data sheet I read two previous questions [this][1] and [this][2]. there two way to do this one way is Right click your pivot table -> pivotTable Options -> Data -> Check Refresh Data when opening File this is working I want a automated way so I tried in this way FileInputStream inputStream = new FileInputStream(new File(excelFilePath)); workbook = new XSSFWorkbook(inputStream); XSSFSheet sheet = workbook.getSheet("Summary"); XSSFPivotTable