I am trying to have a rolling average of all the highs of [‘RSIndex’] greater than 52, series will have NaN value if the first ref value is less than 52, but I want to have the previous iterated value of [‘high_r’] that the function has generated if any other ref value is less than 52.…
Tag: pandas
Pandas generate numeric sequence for groups in new column
I am working on a data frame as below, I want to create a new column with the sequence value for Column B subgroups based on Column A groups like below I tried this , but does not give me desired output Answer IIUC, I think you want something like this: Output:
How do you cumulatively aggregate string in pandas?
I have a column that contains strings. I want to cumulatively aggregate the string through the y-axis. This is the desired output. Something like this can be achieved using the expanding or cumsum() function, however it appears to work for numeric attributes only. Answer a quick idea output: or just: output:
Pandas how to explode several items of list for each new row
I have a dataframe: I want explode it such that every 3 elements from each list in the column l will be a new row, and the column for the triplet index within the original list. So I will get: What is the best way to do so? Answer Break list element into chunks first and then explode: If you
I’m trying to create a table from text
I want to create a table with two columns separated by “:”. So the capitalized words as the first column and everything after the “:” as the second column. I was originally tried to do this from a PDF but that wasn’t working so I copied it to a text file thinking it might be easi…
Transpose both columns and the first row with pandas
Please help transposing this df. Can’t think of better way doing it: df: Yellow marked are column names outcome I’m looking for: Answer try via T attribute,rename_axis(),reset_index() and melt() method: OR via T attribute,rename_axis(),stack(),reset_index() and rename() method:
Extract Value From Pandas Dataframe Based On Condition in Another Column
I am trying to develop some code that extracts the power price when a power plant starts up. To give an example refer to the following data frame. Based on this I aiming to develop some code that would store in a dataframe the power price when the plant ops columns transitions from 0 to a number greater than …
Python dataframe in one column strings delimit by comma, and in another column if pass or fail
How I can count if a country that is in more rows , has failed or passed, enter image description here Like is and the result should be like this enter image description here Because Netherlands is in 4 rows , and has 3 passed and one failed. Answer Use Series.str.split with DataFrame.explode and last call cr…
How do I compare a time value to all the time values in a column in pandas?
I want to apply a condition to a column in a dataframe. The column has time values in the format HH:MM:SS and I want to compare it to a fixed time value(threshold), but I am getting errors. Converting the threshold value to datetime.datetime.strptime gives me error. What I want to ask is – In order to c…
Create forth column based on other columns (lagged) values
I would like to create a forth column “D” which will take a value of 1 if: (at least) two column (A, B, C) have a value of 1 or the previous 2 periods had at least two columns with a value of 1. According to the example above all the rows would have df[‘D’]==1 Answer We can look for