简体   繁体   English

使用熊猫删除CSV文件中的行

[英]Deleting rows in CSV files using Pandas

Relatively new to Pandas so I apologize in advance if this is redundant. 对Pandas来说还不是很新,所以如果这很多余,我先向您道歉。 I have successfully sorted data in my CSV file, but I would like to delete all the rows for which I no longer need. 我已经成功地对CSV文件中的数据进行了排序,但是我想删除不再需要的所有行。 For example here, I would like to keep rows where trade date and settle date are the same but delete rows for which they are different. 例如,在这里,我想保留交易日期和结算日期相同的行,但删除它们不同的行。

Trade Date      Settle Date     Security
 8/15/2017         8/15/2017           a
9/7/2017            9/11/2017          b
8/31/2017          9/6/2017            c

I am guessing I need to add True False Booleans but the code I used to try that did not seem to work for me. 我猜我需要添加True False Boolean,但是我尝试使用的代码似乎对我不起作用。 Any help is appreciated. 任何帮助表示赞赏。

booleans=[]
for length in df_new:
    if 'Trade Date'=='Settle Date':
    booleans.append(True)
else:
   booleans.append(False)
df = df[df['Trade Date'] == df['Settle Date']]
df

  Trade Date Settle Date Security
0  8/15/2017   8/15/2017        a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM