这里是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中筛选出这些行,请执行以下操作:
另外,如果有帮助的话(我也在这周开始使用熊猫),这里有一个非常快速和不错的教程:
http://manishamde.github.io/blog/2013/03/07/pandas-and-python-top-10/ (那不是我!)你知道吗
通读一遍。然后使用pandas search创建一个新的数据帧。最后存储新帧
相关问题 更多 >
编程相关推荐