python-如果一列中有某个值,如何导入csv跳过行?

Python n00b,在这里.我正在使用csv文件中的事件数据.我正在编写一个可更改列顺序并按时间排序的脚本.脚本的该部分有效,但是我想根据一列的值过滤掉某些行:

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

如果我不想使用Org1,该如何过滤该组会议的行.

我正在使用熊猫:

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)

谢谢

解决方法:

要从df中过滤掉这些行,请执行以下操作:

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

另外,如果有帮助(本周我也开始使用Pandas),这里有一个非常快速和不错的教程:

http://manishamde.github.io/blog/2013/03/07/pandas-and-python-top-10/
(不是我!)

相关文章

转载:一文讲述Pandas库的数据读取、数据获取、数据拼接、数...
Pandas是一个开源的第三方Python库,从Numpy和Matplotlib的基...
整体流程登录天池在线编程环境导入pandas和xrld操作EXCEL文件...
 一、numpy小结             二、pandas2.1为...
1、时间偏移DateOffset对象DateOffset类似于时间差Timedelta...
1、pandas内置样式空值高亮highlight_null最大最小值高亮背景...