vendredi 1 juillet 2016

Deleting rows with certain keywords of csv file


I have a large data file and I need to delete rows that have certain keywords.

Here is an example of the file I'm using:

User Name     DN
MB31212       CN=MB31212,CN=Users,DC=prod,DC=trovp,DC=net
MB23423       CN=MB23423 ,OU=Generic Mailbox,DC=prod,DC=trovp,DC=net
MB23424       CN=MB23424 ,CN=Users,DC=prod,DC=trovp,DC=net
MB23423       CN=MB23423,OU=DNA,DC=prod,DC=trovp,DC=net
MB23234       CN=MB23234 ,OU=DNA,DC=prod,DC=trovp,DC=net

This is how I import file:

import pandas as pd
df = pd.read_csv('sample.csv', sep=',', encoding='latin1')

How can I

  1. Delete all rows that contain 'OU=DNA' in DN column for example?
  2. How can I delete the first attribute 'CN= x' in the DN column without deleting the rest of the data in the column?

I would like to get something like what is posted below, with the 2 rows that contained 'OU=DNA' deleted and the 'CN=x' deleted from every row:

User Name     DN
MB31212       CN=Users,DC=prod,DC=trovp,DC=net
MB23423       OU=Generic Mailbox,DC=prod,DC=trovp,DC=net
MB23424       CN=Users,DC=prod,DC=trovp,DC=net

Aucun commentaire:

Enregistrer un commentaire