[enter image description here]
IMAGE 2 (results) enter image description here
2I'm working with data manipulation in csvs using python + pandas. Example #s
I have used if statements in the past however this one is very specific and I can't seem to get the syntax working correctly.
If you look at the code I want column '
T' to be calculated like this
there are a few numbers filled into the row already from previous code and the rest are blank.
The code working will hypothetically run through the rows in column t.
The first rows are mostly blank so it will skip those until it hits a row that has a number in it.
if(df['T'].iat[x-1] != "")
once it hits the row with a number in it the script will check the logical (if the cell in the row next to it is greater than the cell above it)(if
df['PL'].iat[x] > df['PL'].iat[x-1]
if that logical is true it will print the cell from next to it over into the column.
df['T'].iat[x] = df['PL'].iat[x]
and if the logical is false then the cell stays blank
I think the real issue is how it iterates after that step. Right now I think its going back and just checking the last if statement again but I want it to iterate through all of them for each row.
It should read the column above to see if it is blank or filled in and then go through the if statements again only printing a number when all are met.
I have tried multiple arrangements as well as using and/or statements. I just can't seem to get it to print the right results.
import pandas as pd import csv df=pd.read_csv(filename) len1 = len(df) for x in range(len3): if (df['T'].iat[x-1] != ""): if(df['T'].iat[x] == ""): if (df['PL'].iat[x] > df['PL'].iat[x-1]): df['T'].iat[x] = df['PL'].iat[x]
The code displays no error messages however it is not printing the right results. Please let me know if I can explain it any better or if anyone has any ideas. Thanks!