transpose

How can I keep both column value aligned after transposing?

How can I keep both column value aligned after transposing? Question: My Data: “`data = { ‘Col1’: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, …

Total answers: 1

Confused about creating a result matrix for NxN matrix transposition in Python

Confused about creating a result matrix for NxN matrix transposition in Python Question: NxN Matrix transposing gives wrong answers upon making "result" matrix = input matrix Novice programmer here. I am trying to transpose a NxN matrix. Putting the code here to make the problem clear: def flippingMatrix(matrix): result=[[0 for i in range(len(matrix))] for j …

Total answers: 2

How to stack columns to rows in Python?

How to stack columns to rows in Python? Question: For example, the data structrue is like below. import pandas as pd source={ ‘Genotype1’:["CV1","CV1","CV1","CV1","CV1"], ‘Grain_weight1’:[25,26,30,31,29], ‘Genotype2’:["CV2","CV2", "CV2","CV2","CV2"], ‘Grain_weight2′:[29,32,33,32,30] } df=pd.DataFrame(source, index=[1,2,3,4,5]) df and now I’d like to transpose two columns to rows like below. Could you let me know how to do that? Thanks, Asked By: …

Total answers: 2

Pandas – Compute sum of a column as week-wise columns

Pandas – Compute sum of a column as week-wise columns Question: I have a table like below containing values for multiple IDs: ID value date 1 20 2022-01-01 12:20 2 25 2022-01-04 18:20 1 10 2022-01-04 11:20 1 150 2022-01-06 16:20 2 200 2022-01-08 13:20 3 40 2022-01-04 21:20 1 75 2022-01-09 08:20 I would …

Total answers: 3

transpose pandas df based on multiple header rows

transpose pandas df based on multiple header rows Question: I have the following df from a vendor: Unnamed: 0 Unnamed: 1 Unnamed: 2 agg metrics 10/20/22 10/20/22 10/21/22 10/21/22 title content title season episode start hours start hours book blue 1 3 2 2 5 2 movie orange 2 4 11 4 7 4 I …

Total answers: 2

How to transpose a list of lists?

How to transpose a list of lists? Question: Let ll be a list of lists, and tt a tuple of tuples Input: ll = [["a1","a2"],["b1","b2"],["c1","c2"]] Desired output: tt = (("a1","b1","c1"),("a2","b2","c2")) I have managed to solve it for a list of two-element lists, meaning that the internal list only contained two elements each. def list_of_list_to_tuple_of_tuple(ll): first_elements …

Total answers: 3

Reshape pandas DataFrame from wide to long by splitting column names into variable and label

Reshape pandas DataFrame from wide to long by splitting Question: I am trying to reshape the following data from wide to long format df = pd.DataFrame( { "size_Ent": { pd.Timestamp("2021-01-01 00:00:00"): 600, pd.Timestamp("2021-01-02 00:00:00"): 930, }, "size_Baci": { pd.Timestamp("2021-01-01 00:00:00"): 700, pd.Timestamp("2021-01-02 00:00:00"): 460, }, "min_area_Ent": { pd.Timestamp("2021-01-01 00:00:00"): 1240, pd.Timestamp("2021-01-02 00:00:00"): 1503, }, "min_area_Baci": …

Total answers: 2

How to reformat horizontal csv to a more vertical format

How to reformat horizontal csv to a more vertical format Question: The above CSV is just a small snippet of the data, there are lots of data entries. A simple transpose will not work I need to get into the following format: I have tried some methods with pandas and transpose but cannot figure it …

Total answers: 3

How do I multiply two matrices in pyhton without numpy?

How do I multiply two matrices in pyhton without numpy? Question: Implement a function mat_mult_by_transpose(mat) which gets a valid matrix called mat and returns a new matrix which is the matrix multiplication of and ( ) , i.e. ( ) ⋅ ( ) . Return a new matrix, without modifying mat2. You may assume that …

Total answers: 1

transposing data based on column value using python

transposing data based on column value using python Question: I have web traffic data for a different channel. I want to transpose based on the channel name and get multiple time series. day main_channel visits CR 11/2/2022 a 443645 1.248513488 11/2/2022 b 382870 3.441750617 11/2/2022 c 51249 0.315164766 11/1/2022 a 390267 2.725545677 11/1/2022 b 15361 …

Total answers: 1