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),这里有一个非常快速和不错的教程:
标签:pandas,csv,python
来源: https://codeday.me/bug/20191122/2057128.html