[英]Passing out to_csv with specific delimiter, losing the header in the process
Hello everyone as i was passing my df to csv, which has a header.Here a pic for proof.大家好,因为我正在将我的 df 传递给 csv,它有一个 header。这里有一张照片作为证据。
Interesting enough as i was passing this csv, with a specific delimiter.很有趣,因为我正在通过带有特定分隔符的 csv。 Because it has a json response and it basically bugs out with comas.
因为它有一个 json 响应,它基本上会出现昏迷。 It returns with no header, does anyone know the probable reason?
它返回时没有 header,有人知道可能的原因吗?
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='|')
NumPy has no header names, so when you convert it from Pandas it loses the headers. NumPy 没有 header 名称,因此当您从 Pandas 转换它时,它会丢失标题。
You can use instead:您可以改用:
prod.to_csv(r'D:/Queries Claro/Dados_limpos.csv', sep='|')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.