Last Updated: February 25, 2016
·
2.261K
· paulofilip3

remove BOM in columns (pandas, python)

import pandas as pd
import re

table = pd.read_csv('some_file_with_BOM.csv', sep=',', encoding='utf-16-le')

regex = '([a-zA-Z0-9_-])' # You can add any other character you wish to keep

table = table.rename(columns=dict((col, ''.join(re.findall(regex, col))) for col in table.columns))