I have some problems and hope that you can help me. The data goes as follows:
The column are labeled as height and the numbers are the available data for that timeframe. So for example for the first row, at the height of 288m only 10% of the data is available (the other 90% was not able to be measured)
I want to set a threshhold value, for example 80. So only heights which contain at least 80% of available data should be included. For each row I want to find the last value for which >= 80 is still true. The height in which this value was found should then be added to a new column.
I can show the rows with: df.iloc[0], this would get me all the values of the first row... normally I would write a loop but since this is Pandas DataFrame there should be a more convenient option for getting the last value for which the condition >= 80 is true.
The Pseudocode would look like this:
- for every row in the data frame check if value is >= 80
- extract the column name for the last value this condition true
- append this value to a new column called 'height value'
I hope I made myself somewhat clear. I am quite new to pandas and seem to struggle quite a bit with data extraction based on conditional expression.
EDIT:
The pandas code for the first 3 rows is: (time index is not important so I didn't include it)
pdf = pd.DataFrame([[100.0, 100.0, 100.0, 100.0, 100.0, 99.0, 97.0, 93.0, 71.0, 45.0, 27.0, 10.0],
[100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 94.0, 81.0, 62.0, 36.0, 9.0],
[100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 92.0, 90.0, 68.0, 45.0, 25.0, 13.0]],
columns=[40.0, 58.0, 78.0, 98.0, 118.0, 138.0, 163.0, 178.0, 198.0, 228.0, 248.0, 288.0])
EDIT 2: The output data should look like this:
result = pd.DataFrame([[100.0, 100.0, 100.0, 100.0, 100.0, 99.0, 97.0, 93.0, 71.0, 45.0, 27.0, 10.0, 178.0],
[100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 94.0, 81.0, 62.0, 36.0, 9.0, 198.0],
[100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 92.0, 90.0, 68.0, 45.0, 25.0, 13.0, 178.0]],
columns=[40.0, 58.0, 78.0, 98.0, 118.0, 138.0, 163.0, 178.0, 198.0, 228.0, 248.0, 288.0,'max_available_height'])