Empty pivot table with pandas data frames

I have checked around, but it seems I can’t find this question (or at least an answer) anywhere. Say I have this data frame with empty cells data = pd.DataFrame( {‘A’: {0: ‘a1’, 1: ‘a1’, 2: ‘a1’, 3: ‘a1’, 4: ‘a1’, 5: ‘a2’, 6: ‘a2’, 7: ‘a2’, 8: ‘a2’, 9: ‘a2’}, ‘B’: {0: nan, 1:… Read More Empty pivot table with pandas data frames

postgres crosstab return 3 columns, how to add more column

My question is similar to this but the answer didn’t work in my case. Here’s my table. CREATE TABLE response(session_id int, seconds int, question_id int, response varchar(500),file bytea); INSERT INTO response(session_id, seconds, question_id, response, file) VALUES (652,1459721866,31,0,NULL),(652,1459721866,32,1,NULL),(652,1459721866,33,0,NULL), (652,1459721866,34,0,NULL),(652,1459721866,35,0,NULL),(652,1459721866,36,0,NULL), (652,1459721866,37,0,NULL),(652,1459721866,38,0,NULL),(656,1460845066,31,0,NULL), (656,1460845066,32,0,NULL),(656,1460845066,33,0,NULL),(656,1460845066,34,0,NULL), (656,1460845066,35,1,NULL),(656,1460845066,36,0,NULL),(656,1460845066,37,0,NULL), (656,1460845066,38,0,NULL),(657,1463782666,31,0,NULL),(657,1463782666,32,0,NULL), (657,1463782666,33,0,NULL),(657,1463782666,34,0,NULL),(657,1463782666,35,1,NULL), (657,1463782666,36,0,NULL),(657,1463782666,37,0,NULL),(657,1463782666,38,0,NULL) The following query works, SELECT * FROM crosstab (‘select session_id, question_id,… Read More postgres crosstab return 3 columns, how to add more column

MySQL add columns from query results

I’d like to add/create three columns from table column based on this particular column results. This is the records I’ve in a tblexammarks: SELECT exm.ID, exm.Admission_No, exm.Subject AS ‘SID’, sb.Name AS ‘Subject Name’, exm.Term, exm.Test, exm.Marks FROM tblexammarks exm INNER JOIN tblsubjects sb ON exm.Subject=sb.ID ORDER BY exm.ID ASC; Output: ID Admission_No SID Subject Name… Read More MySQL add columns from query results