Python Forum
PANDAS: DataFrame | Saving the wrong value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PANDAS: DataFrame | Saving the wrong value
#1
I have a column called 'cnpjfornecedor' the original value is 08.482.581/0001-57 i need to remove the special caracters to have 08482581000157

i'm using this code

## /*-+.,<>;:\'@#$%¨&"=()+ and strip á é í ó ú

#ficou fora = valorvenda, valorcusto, codfranqueadora,unidademedida, percroyalties, 

dados1 = {'\\': '', '*': '', '-': ' ','+': '', '.': '', ',': '', '<': '', '>': '', ';': '', ':': '','\'': '', '@': '', '#': '',
        '$': '', '%': '', '¨': '', '&': '', '=': '', '(': '', ')': '', 'á': 'a', 'é': 'e', 'í': 'i', 'ó': 'o', 'ú': 'u', 
        'Á': 'A', 'É': 'E', 'Í': 'I', 'Ó': 'O', 'Ú': 'U'}

dados2 = {'/': '', '-': '', '.': '', ',': ''}

for old, new in dados1.items():
    df['modelo']=df['modelo'].str.replace(old, new, regex=False)
    df['referencia']=df['referencia'].str.replace(old, new, regex=False)
    df['ean']=df['ean'].replace(old, new, regex=False)
    df['codncm']=df['codncm'].replace(old, new)
    df['descricao']=df['descricao'].str.replace(old, new, regex=False)
    df['cor']=df['cor'].str.replace(old, new, regex=False)
    df['tamanho']=df['tamanho'].replace(old, new, regex=False)
    df['linha']=df['linha'].str.replace(old, new, regex=False)
    df['artigo']=df['artigo'].str.replace(old, new, regex=False)
    df['genero']=df['genero'].str.replace(old, new, regex=False)
    df['material']=df['material'].str.replace(old, new, regex=False)
    df['faixa']=df['faixa'].str.replace(old, new, regex=False)
    df['colecao']=df['colecao'].str.replace(old, new, regex=False)
    df['origem']=df['origem'].str.replace(old, new, regex=False)
    df['marca']=df['marca'].str.replace(old, new, regex=False)
    df['compartigo']=df['compartigo'].replace(old, new, regex=False)
    df['cnpjloja']=df['cnpjloja'].replace(old, new, regex=False)
    
for old, new in dados2.items():
    df['cnpjfornecedor']=df['cnpjfornecedor'].str.replace(old, new, regex=False)


the result in jupyter is showing the right answer but when i save the new file using this code:

df.to_csv('finalfodastico.csv', sep=';', index=False)
the value that shows in the csv column is:
8,48258E+12 in the cell and 8482581000157 in the line.
idk why it removes the first caracter that is 0 and how can i set to show the right value in the column?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  HTML Decoder pandas dataframe column mbrown009 3 962 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  Use pandas to obtain cartesian product between a dataframe of int and equations? haihal 0 1,091 Jan-06-2023, 10:53 PM
Last Post: haihal
  Pandas Dataframe Filtering based on rows mvdlm 0 1,396 Apr-02-2022, 06:39 PM
Last Post: mvdlm
  Pandas dataframe: calculate metrics by year mcva 1 2,269 Mar-02-2022, 08:22 AM
Last Post: mcva
  Pandas dataframe comparing anto5 0 1,243 Jan-30-2022, 10:21 AM
Last Post: anto5
  PANDAS: DataFrame | Replace and others questions moduki1 2 1,758 Jan-10-2022, 07:19 PM
Last Post: moduki1
  update values in one dataframe based on another dataframe - Pandas iliasb 2 9,100 Aug-14-2021, 12:38 PM
Last Post: jefsummers
  empty row in pandas dataframe rwahdan 3 2,419 Jun-22-2021, 07:57 PM
Last Post: snippsat
Question Pandas - Creating additional column in dataframe from another column Azureaus 2 2,916 Jan-11-2021, 09:53 PM
Last Post: Azureaus
  Comparing results within a list and appending to pandas dataframe Aryagm 1 2,320 Dec-17-2020, 01:08 PM
Last Post: palladium

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020