Home > database >  Passing out to_csv with specific delimiter, losing the header in the process
Passing out to_csv with specific delimiter, losing the header in the process

Time:01-11

Hello everyone as i was passing my df to csv, which has a header.Here a pic for proof. enter image description here

Interesting enough as i was passing this csv, with a specific delimiter. Because it has a json response and it basically bugs out with comas. It returns with no header, does anyone know the probable reason?

Here is the code

# Prod is the df
my_numpy = prod.to_numpy()
np.savetxt(r'D:/Queries Claro/Dados_limpos.csv', my_numpy,fmt='%s', delimiter='|')

CodePudding user response:

NumPy has no header names, so when you convert it from Pandas it loses the headers.
You can use instead:

prod.to_csv(r'D:/Queries Claro/Dados_limpos.csv', sep='|')
  •  Tags:  
  • Related