How to look for words despite being in uppercase or lowercase using pandas?

Viewed 82

How can I improve my search of words so that even if they are in uppercase or lowercase can be recognized as the same, using pandas?

As you can see in the image I have: .xls and XLS.

import pandas as pd

df = pd.DataFrame({'file_name': ['filelist.xml', 'sheet002', 'sheet005.htm', 'image1.jpg', 'image3.jpg',
   'kings.xls', 'Kings.XLS', 'Kings', 'Riders', 'Royals.pdf', 'Royals.csv', 'Riders.xml'],
   'created_at': ['2020-01-01 23:00:34'] *2 + ['2018-01-01 13:01:34'] *3 + ['2020-01-01 22:00:00'] *4 + ['2018-02-01 23:00:34']*3,
   'size':[8760] * 3 + [789] *4 + [863] *2 + [673] *3})


(df['size'].groupby(df.file_name.str.extract(r'(\.\w+$)', expand=False)
           .fillna('unknown'))
           .sum().plot.pie())

enter image description here

1 Answers
(df['size'].groupby(df.file_name.str.lower().str.extract(r'(\.\w+$)', expand=False)
           .fillna('unknown'))
           .sum().plot.pie())

enter image description here

Related