Hello, i'm trying to create a script that parse the CSV.
This is what i got at moment.
Y'all have any ideia and suggestions to increase the quality of my code?
This is what i got at moment.
#### Importando arquivo CSV import pandas as pd #data = pd.read_csv(r'promocao.csv', encoding='unicode_escape') #df = pd.DataFrame(columns=['descricao', 'artigo']) df = pd.read_csv(r"C:\Users\Bruno Nyland\Jupyter\teste.csv",sep=';', encoding= 'utf-8') df[:10] #### Ajustando o nome das colunas df.columns =[x.lower().replace("_","").replace("?","").replace("*","") \ .replace("¹","").replace("²","").replace("³","") \ .replace("ã","a").replace("ç","c")for x in df.columns] df.columns #### Definindo as colunas. df.columns = ['modelo', 'referencia', 'ean', 'codncm', 'descricao', 'cor', 'tamanho', 'valorvenda', 'valorcusto', 'linha', 'artigo', 'genero', 'material', 'faixa', 'colecao', 'cnpjfornecedor', 'codfranqueadora', 'unidademedida', 'percroyalties', 'origem', 'marca', 'compartigo', 'cnpjloja', 'pesobruto', 'pesoliquido', 'placeholder1', 'placeholder2'] df[:10] #### Validando os dados ####descricao = /*-+.,<>;:\'@#$%¨&"=()+ and strip á é í ó ú <--- I NEED TO REMOVE THIS CHARACTERS FROM THE STRING df['modelo'] = df['modelo'].str.replace("/","").str.replace("*","").str.replace("-","").str.replace("+","").str.replace(".","") \ .str.replace(",","").str.replace("<","").str.replace(">","").str.replace(";","").str.replace(":","") \ .str.replace("'","").str.replace("@","").str.replace("#","").str.replace("$","").str.replace("%","").str.replace("¨","") \ .str.replace(""\"","").str.replace("&","").str.replace("""""","").str.replace("=","").str.replace("(","").str.replace(")","") \ .str.replace("á","a").str.replace("é","e").str.replace("í","i").str.replace("ó","o").str.replace("ú","u") \ .str.replace("Á","A").str.replace("É","E").str.replace("Í","I").str.replace("Ó","O").str.replace("Ú","U") ERROR: File "C:\Users\BRUNON~1\AppData\Local\Temp/ipykernel_12440/625730687.py", line 8 .str.replace(""\"","").str.replace("&","").str.replace("""""","").str.replace("=","").str.replace("(","").str.replace(")","") \ ^ SyntaxError: unexpected character after line continuation character #### Remover espaços em branco df['modelo'] = df['modelo'].str.strip() df['referencia'] = df['referencia'].str.strip() df['descricao'] = df['descricao'].str.strip() #### Salvar o resultado final df.to_csv('finalfodastico.csv',sep=';', index=False)I need to remove that group os special caracters from the string but this error:
Error:ERROR: File "C:\Users\BRUNON~1\AppData\Local\Temp/ipykernel_12440/625730687.py", line 8
.str.replace(""\"","").str.replace("&","").str.replace("""""","").str.replace("=","").str.replace("(","").str.replace(")","") \
^
SyntaxError: unexpected character after line continuation character
Y'all have any ideia and suggestions to increase the quality of my code?
Larz60+ write Jan-09-2022, 10:46 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.