transform

How can I transform a table so the column headers go into the table and the table values become column headers?

How can I transform a table so the column headers go into the table and the table values become column headers? Question: How can I use pandas in Python to make this table: data = [[‘4/04/2023′,’Floors’,’Tables’,’Roof’,’Paint’,”],[‘4/05/2023′,”,’Floors’,’Tables’,’Roof’,’Paint’],[‘4/06/2023′,’Paint’,”,’Floors’,’Tables’,’Roof’],[‘4/07/2023′,’Roof’,’Paint’,”,’Floors’,’Tables’]] df = pd.DataFrame(data, columns=[‘Date’, ‘Jim’,’Bob’,’Ed’,’James’,’Joe’]) Look like this? I think I have to use melt and Pivot, but I …

Total answers: 2

How to save image with same name with python?

How to save image with same name with python? Question: I have image folder as below : |——dir–| | |—- input–|– 1.jpg | | |– 2.jpg .. … … … where I want to do random rotation for input folder and save the results in output folder I tryied the fillowing script : import torch …

Total answers: 1

transform colors in colorbar, not the ticks

transform colors in colorbar, not the ticks Question: When using a custom normalization, for instance PowerNorm, we can adjust the mapping between values and the colors. If we then show a corresponding colorbar, we can see the change when observing the ticks (compare left and right plot in the following picture). Is there a way …

Total answers: 1

XML Transform with Python

XML Transform with Python Question: I have a XML file like this: <recommendations> <para> <text>Text.</text> </para> <para> <text>Text2.</text> </para> </recommendations> I want to make a new recommendations tag with "Text" concatenate with "Text2" using python: Text.Text2. can someone help me? I tried so far: xml_parsed = ET.parse(file) xml_parsed_root = xml_parsed.getroot() recommendations_root = item.findall(r’recommendations’) for para …

Total answers: 1

Fixed shift applied to text coordinates with matplotlib

Fixed shift applied to text coordinates with matplotlib Question: I’m writing a function based on matplotlib.pyplot that mimics academic plots, i.e. with arrow axes and labels slightly shifted from each arrow head. I’ld like to place some text shifted from the arrow heads (e.g. 10 pixels up or right), and that shift to be constant, …

Total answers: 1

How I can transfer matrix in Python?

How I can transfer matrix in Python? Question: #Example: A = [[1,2,3,4],[4,3,2,1],[3,2,1,4],[2,1,4,3]] #How I can transform matrix A become matrix B #with matrix B I want to become… B = [[1], [2], [3], [4], [4], [3], [2], [1], [3], [2], [1], [4], [2], [1], [4], [3]] And when I save .txt or .csv how I …

Total answers: 2

Subtract value from particular row using groupby transform

Subtract value from particular row using groupby transform Question: Have a dataframe containg several groups (column Id). Within each group there are several levels (column Level). All groups have a level named ‘Base’. For each group I want to subtract the ‘Base’ value from the value at all the other levels. Using pandas.join and a …

Total answers: 2

Transform dataframe value to range value in Python 3

Transform dataframe value to range value in Python 3 Question: I have a dataframe with the values: 3.05 35.97 49.11 48.80 48.02 10.61 25.69 6.02 55.36 0.42 47.87 2.26 54.43 8.85 8.75 14.29 41.29 35.69 44.27 1.08 I want transform the value into range and give new value to each value. From the df we …

Total answers: 2

Transform pandas DataFrame from wide to long and count occurrences of a unique value

Transform pandas DataFrame from wide to long and count occurrences of a unique value Question: I have a pretty specific problem that I sadly can not work my mind around. The DataFrame I want to transform currently looks like this: df_larceny CATEGORY INCIDENTYEAR INCIDENTMONTH LARCENY 2009 1 LARCENY 2009 1 LARCENY 2009 1 ……………………….. ……………………….. …

Total answers: 1