Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to rename columns with a delimeter

Index(['id', 'asins', 'brand', 'categories', 'colors', 'count', 'dateAdded',
   'dateUpdated', 'descriptions', 'dimension', 'ean', 'features',
   'flavors', 'imageURLs', 'isbn', 'keys', 'manufacturer',
   'manufacturerNumber', 'merchants', 'name', 'prices.amountMin',
   'prices.amountMax', 'prices.availability', 'prices.color',
   'prices.condition', 'prices.count', 'prices.currency',
   'prices.dateAdded', 'prices.dateSeen', 'prices.flavor', 'prices.isSale',
   'prices.merchant', 'prices.offer', 'prices.returnPolicy',
   'prices.shipping', 'prices.size', 'prices.source', 'prices.sourceURLs',
   'prices.warranty', 'quantities', 'reviews', 'sizes', 'skus',
   'sourceURLs', 'upc', 'vin', 'websiteIDs', 'weight'],
  dtype='object')

I have columns with . in them, how do I rename them to have only the part after the dot?

I can rename them manually, but what is the better way to do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can split the strings on the . and keep only the last item, like so:

df.columns = [col.split('.')[-1] for col in df.columns]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading