Home > other >  Filtering data from excel
Filtering data from excel

Time:06-14

I'm trying to create first version of working program that would read through data from excel and filter those numbers. My sensor is falty so sometimes jumps to very high numbers.

I've managed to read files and code filters numbers but problem is i have to run last few lines of code twice. On first try nothing happens.

Can somebody explain or help with example what I'm doing wrong? I guess im tring to delete number im itterating over, but I don't know how to work around it. 8Maybe somehow when converting to dict if i can sort those numbers?)

EDIT: picture of folder Data in Excel file

For school, I'm trying to read through multiple excel data, take values from first 3 colums. In second column is data of path traveled, which shows faulty values. I want to find those faulty values and remove those values and values of Force and time associated with them. (as per picture2 im trying to remove all data from first rows).

I'll use those data in further graph drawings and approximations and some calculations, but first i need to have list of data that is ok.

Thank you!

i = 1
rotorji = {} #open empty dic
rotor = {} #open empty dic
if rotorji is {}:
    rotorji.clear()
else:
     rotorji = {} #if i forget to clear dic

for file in os.listdir():
   if file.endswith(".xlsx"):
       rotorji[i] = {}
       rotor[i] = {}
       rotorji[i] = pd.read_excel(file, usecols=(0, 1, 2), names = ('Time','Path','Force'))
       rotor[i] = rotorji[i].to_dict('list')
       i = i 1


try:
    del i
except NameError:
    pass
try:
    del j
except NameError:
    pass

try:
    del v
except NameError: #celaring variables
    pass

for i in rotor:
    for v in rotor[i]['Path']: #for value in dictionari of key path
        if v < 0.0 or v > 400.0 :
            rotor[i]['Force'].pop(rotor[i]['Path'].index(v))
            rotor[i]['Time'].pop(rotor[i]['Path'].index(v))
            rotor[i]['Path'].pop(rotor[i]['Path'].index(v))

CodePudding user response:

If I understand you right, you want to filter out above a certain threshold values in your 'Untitled 1' column. If this is the case and you have all your data in a dataframe, this will do the job:

threshold = 1000
df = df[df['Untitled 1'] < threshold]
  • Related