Filter CSV File with Pandas/Python -


i have csv file, wanted filter keep rows have values in row "d" bigger 0.

file:

  index  value    d 0    975  25.35   5 1    976  26.28   4 2    977  26.24   1 3    978  25.76   0 4    979  26.08   0 

i used pandas that, didn't work out:

df = pd.read_csv("thisfilel.csv") df = df[(df["d"]>0)] 

i used other approach well, it's long process file of 600mb.

with open("thisfilel.csv", 'rb') source:     writer = csv.writer(source)     line in source:         if line.d > 0 :               writer.writerow(headers) 

sorry, no pandas solution, kind of task basic unix tools cannot beaten. if use windows can same cygwin:

$ awk '{if ($4 > 0) print $0}' t.csv    0    975  25.35   5   1    976  26.28   4   2    977  26.24   1 

you can filter data in desired way, save file, , read in using pandas:

$ awk '{if ($4 > 0) print $0}' t.csv >filtered.csv 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -