Member
i need help with this code in vs code:


import pandas as pd
import json
import re
from openpyxl.utils.exceptions import IllegalCharacterError


Read the JSON file into a pandas DataFrame

with open('phishfold1.json') as f:
    data = pd.DataFrame([json.loads(line) for line in f])


Remove or replace illegal characters from column names and data

data.columns = data.columns.map(lambda x: re.sub(r'[<>:"/\|?]', '', x))
data = data.replace(r'[<>:"/\|?]', '', regex=True)


Convert the DataFrame to an XLSX file

try:
    data.toexcel('phishfold_5.xlsx', index=False)
except IllegalCharacterError as e:
    print("Illegal characters found in the data. Please remove or replace them.")


i get this error:
PS C:\Users\silja\Desktop\Háskóli Íslands\Öryggisgreining\Silja-Action-item4\data>  & 'C:\Python311\python.exe' 'c:\Users\silja.vscode\extensions\ms-python.python-2023.8.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '57418' '--' 'C:\Users\silja\Desktop\Háskóli Islands\Öryggisgreining\Silja-Action-item4\data\convert.py'
Illegal characters found in the data. Please remove or replace them.


this is how my JSON file looks like:
{"text":"---------- Forwarded message ----------\r\nFrom: Chris Fairbourn\r\nDate: May 8, 2008 6:34 AM\r\nSubject: Texas\r\nTo: <PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>\r\nhit me up when yall come back down to Austin Texas so i can join yall im\r\ntired of all these dam beaners and niggers that have turned downtown austin\r\ninto garbage i cant go down there without seein a nigger being a damn pourch\r\nmonkey\r\nheil hitler\r\nhope to here from u soon\r\n--\r\nCommander Jeff Schoep\r\n\"If you are not part of the solution, you are part of the problem.\"\r\nNational Socialist Movement www.nsm88.org\r\nThe information in this email is confidential and may be legally privileged.\r\nFurthermore, the NSM is not responsible for the content of this e-mail, and\r\nanything written in this e-mail does not necessarily reflect the NSM's views\r\nor opinions. Access to this email by anyone other than the intended\r\naddressee is  unauthorized. If you are not the intended recipient of this\r\nmessage, any review, disclosure, copying, distribution, retention, or any\r\naction taken or  omitted to be taken in reliance on it is prohibited and may\r\nbe unlawful. If you have received this mail in error, please destroy the\r\ncopy in your  possession and notify: <PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>","is_deceptive":false}