0

I've made this short code for a little home project I'm doing to give me the index numbers of values of different columns in a .csv file not equal to 1 which I then use to find another linked value in a .txt file using said index value.

df = pd.DataFrame(pd.read_csv('Results.csv',  sep=','))
df1 = df.loc[df["Results 1"] != 1, 'Results 1']
print(df1)

Which gives me this,

335    0.962
436    0.990
898    0.990

I then manually pick out the index values to find the linked values in the .txt file using this,

df2 = pd.read_csv('Results 1.txt', header=None, skiprows=1, usecols=[1], sep='\t')
print(df2[335:336], df2[436:437], df2[898:899])

Which gives me,

         1
335  3.022          1
436  3.522          1
898  3.483

I have 100 files I'm trying to repeat this process for and want to plot all of the results on a singular plot.

I was wondering if you guys could help me understand how to setup a loop or an if statement that I could use so that I'm not just copy and pasting the code 100 times. If you guys have any links to helpful webpages or any tips that'd be super helpful!

TIA

Notes:

The .csv file holds results from all the .txt files which I'm using to find the index value.

All the results folders are named "Results #.txt" numbered 1 - 100

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
RJPython
  • 43
  • 6

0 Answers0