mercredi 1 septembre 2021

Python : How to make python delete files in the directory when a if statement is satisfied? [closed]

import pandas as pd
from astropy.timeseries import LombScargle
import matplotlib.pyplot as plt 
import numpy as np
from astropy import stats

mylist = [  1837214300016435  ,  1837214300018210  ,  1837214300018256  ,  1837214300018515  ]

for x in mylist:
  data= pd.read_csv(("{0}.csv").format(x),usecols=[3,4,5])
  names = data.columns

  df = pd.DataFrame(data, columns=names)
  df.head()

  #print(df)

  if df['magerr'].mean() <0.1 :
   os.remove({0}.csv).format(x)

My goal is to delete those csv files from my directory which satisfy the if statement ie. mean<0.1

I have tried in this fashion but it just gives this error : 'set' object has no attribute 'csv'

Aucun commentaire:

Enregistrer un commentaire