python read a DF of strings id,text…
- User
python
read a DF of strings
id,text
2,{"categoryID":9,"params":{"110000":"MTgwNDQ3Mjk=","110001":"MTg3NDUzNTE=","110006":"MzMxMjUw"}} 3,{"categoryID":9,"params":{"1283":"MTQ3NTY=","110000":"MzI5Mjg2","110001":"MzI5OTc2","110007":"WzMzMTI1MV0="}}
in text
-
replace ',"params* ' to '' (* is regexp any symbols)
-
replace '{"categoryID": ' to ''
-
save result to 'ID' as INT , save to column 'result1;
-
replace '"params": ' to '' ( is regexp any symbols), save to column 'result2;
-
- Assistant
To achieve the tasks you've described using Python, you'll need to make use of the pandas library for handling the DataFrame, and the re library for regular expressions. Here's a step-by-step script that processes your DataFrame according to the specified requirements:
python - User
ValueError: invalid literal for int() with base 10: '{"categoryID":9'
- Assistant
The error you're encountering occurs because the substitution in the
result1calculation is leaving remnants of the string, like{"categoryID":9, which cannot be directly converted to an integer. To fix this, we need to ensure that only the numeric part of"categoryID":9is extracted before converting it to an integer.Let me provide you with a refined version of the code:
python