I want to define a function to filling header colour, for now, I am just hard code every object. Here is the code I used, I tried to define a function to add cell colour. The error msg shown below: Could you guys help me to solve this error? I copy this function from https://stackoverflow.com/a/62079054/18540…
Tag: pandas
How to create multiple combinations of columns from a pandas dataframe?
I’ll illustrate my problem with a drawing: I have a pandas dataframe with 13 columns of 6 different types. Then I randomly want to take one of each type and create a new table to perform subsequent analyses. So in the end I want to create (3 choose 1) * 1 * (2 choose 1) * (2 choose 1) *
How to create a new index level with columns name in Pandas?
I would like to add a new level to the index of a dataframe, based on columns name. How can i do that ? Desired result I can build the multiindex with this but how can i create a new dataframe and map the data ? Answer You can use df.stack() Back to your code, you can try numpy.ravel to
how to apply a format on multiple excel files at once (hide gridlines & autofit columns)
I’m trying to apply a specific format on an iterate excel files, i need to hide the gridlines and autofit columns width, i tried many codes and styles but no one of them worked with me. the exported excel files shown as below PSenter image description here Answer Haven’t dealt with excel formattin…
Add a comma after two words in pandas
I have the following texts in a df column: What I need is to add a comma at the end of each row but the condition that it is only two words. I found a partial solution: (solution found in stackoverflow) Answer Given: Doing: Outputs:
Pandas group by one column and repeat the values of another column
I was trying to divide the month into two weeks. Basically for each month i am trying to create week numbers like 1,2,3,4 and repeat them. How to create the required column like below: Answer You can utilize cycle to create cycle for list and slice to get specific count
How to get the week number starting from monday of given month in python?
I was trying to calculate the week number starting from first Monday of October. Is there any functions in pandas or datetime to do the calculation efficiently? MWE Answer Shift dates by the number of days to new year, they use standard Monday week number formatting (%W): The offset in days can be calculated …
Sort multiIndex table based on other table
I have a multiIndex data frame like this and I have another similar table whose index is Patient_1, Patient_2 and Patient_3. I want to order my table like that. Patients are actually names and the number of patients can change depending on the input data. In the table I want to re-order, there are 10 rows per…
Order in dataframe generation
Could you explain to me why the Properties column was the third column and not the first one? As you can see I insert it as the first in pd.DataFrame, but when I do print(df), it appears as the third column. Answer Try using columns argument to assign the order of columns: This gives:
How to access particular elements of a dataframe in Pandas. Gives error
I have a dataframe df_params. It contains parameters for the stored procedure. I simply want to access the elements of the dataframe in a loop: But it gives me an error without really explanation: The goal is to supply value to the stored procedure: desired outcome from print(query): Answer pandas.DataFrames …