How to import csv skip rows if there is a specific value in one column?

Python n00b, here. I work with event data in csv files. I am writing a script that reorders columns and sorts by time. This part of the script works, but I want to filter out specific rows based on the value of a single column:

Description   Date     Start End   Location         Organization
Meeting       2/14/14  9:00  9:30  Conference Room  Org1
Meeting       2/14/14  9:30  10:00 Conference Room  Org2

If I don't want Org1, how can I filter the rows for these group meetings.

I am using pandas:

import pandas as pd
df = pd.read_csv('day_of_the_week.csv')
df = df.sort('MEETING START TIME')
#saved_column = df.column_name #you can also use df['column_name']
location = df.LOCATION
date = df.DATE
starttime = df['MEETING START TIME']
endtime = df['MEETING END TIME']
description = df.DESCRIPTION
organization = df.ORGANIZATION

#write new csv file with new order of columns
df.to_csv('Full_List_sorted.csv', cols=["DATE","MEETING START TIME","MEETING END TIME","DESCRIPTION","ORGANIZATION","LOCATION"],index=False)

thank

+3
source share
2 answers

To filter these lines from df, follow these steps:

df = df[df["Organization"]!="Org1"]

Also, if this helps (I also started using Pandas just this week), there is a very quick and nice tutorial here:

http://manishamde.imtqy.com/blog/2013/03/07/pandas-and-python-top-10/ ( !)

+3

. pandas. ,

0

All Articles