(Pandas) to_scv error in parameter Sep=

Asked

Viewed 103 times

-1

I am trying to play the content of a dataset on an scv, however the parameter SEP =';' stopped working.

df.to_csv(path,r'\20191122_Consolidados_camara_de_retencao.csv', sep = ';')

When trying to run Python command line gives the following error:

to_csv() got multiple values for argument 'sep'

Someone has already been through this problem ? Can you help me understand the mistake ?

Thank you.

  • The second parameter of to_csv already is the sep, then you are passing a value by the position, r'\20191122_Consolidados_camara_de_retencao.csv', and another by the named parameter, sep = ';'. That is, the function call is wrong. I recommend that you review the documentation and see how to properly do what you need.

  • Thank you for the comment Woss, but could you give me an example of how I would pass a separate < ; > in this case ? I even looked at the documentation and in the example this passing the separator as I did. I was confused. rs

  • What is path and r'\20191122_Consolidados_camara_de_retencao.csv' which also passed parameters?

  • path = os.chdir('C: Users ADAMLINCOLNOLIVEIRAS Box Sync Director_camara_de_retencao') e r' 20191122_Consolidados_camara_de_retencao.csv' is the file name I want the file to have as far as I know.

  • But why pass two paths to the function? You should not concatenate them and ride only one way?

  • is why PATH is the path to the folder where other files are. With the command (path, r' 20191122_Consolids_camara_de_retencao.csv') I’m actually mounting a path only: C: Users ADAMLINCOLNOLIVEIRAS Box Sync Director_camara_de_retencao + /20191122_Consolidados_camara_de_retencao.csv This worked before, but Pandas updated and now this different.

  • No, you are passing the two valroes separately to the function, the second being considered as sep. If you want to concatenate, use the operator +

Show 3 more comments

1 answer

1


Use:

df.to_csv('20191122_Consolidados_camara_de_retencao.csv', sep = ';')

This one is saved in the same directory as .py. If you want to set another directory, you can use it for example:

df.to_csv(r'C:\Users\Users\Desktop\20191122_Consolidados_camara_de_retencao.csv', sep = ';')
  • The error was being caused by the attempt to concatenate the File Path (Path) and the file name, so Python identified that I was passing two SEP=parameters, since the first parameter always needs to be a SEP in this case.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.