python的pandas工具包,保存.csv文件时不要表头的实例

yipeiwu_com5年前Python基础

用pandas处理.csv文件时,有时我们希望保存的.csv文件没有表头,于是我去看了DataFrame.to_csv的document。

发现只需要再添加header=None这个参数就行了(默认是True),

下面贴上document:

DataFrame.to_csv(path_or_buf=None, sep=', ', na_rep='', float_format=None, columns=None, header=True, index=True, index_label=None, mode='w', encoding=None, compression=None, quoting=None, quotechar='"', line_terminator='\n', chunksize=None, tupleize_cols=None, date_format=None, doublequote=True, escapechar=None, decimal='.')

Write DataFrame to a comma-separated values (csv) file
path_or_buf : string or file handle, default None
File path or object, if None is provided the result is returned as a string.
sep : character, default ‘,'
Field delimiter for the output file.
na_rep : string, default ‘'
Missing data representation
float_format : string, default None
Format string for floating point numbers
columns : sequence, optional
Columns to write
header : boolean or list of string, default True
Write out the column names. If a list of strings is given it is assumed to be aliases for the column names
index : boolean, default True
Write row names (index)
index_label : string or sequence, or False, default None
Column label for index column(s) if desired. If None is given, and header and index are True, then the index names are used. A sequence should be given if the DataFrame uses MultiIndex. If False do not print fields for index names. Use index_label=False for easier importing in R
mode : str
Python write mode, default ‘w'
encoding : string, optional
A string representing the encoding to use in the output file, defaults to ‘ascii' on Python 2 and ‘utf-8' on Python 3.
compression : string, optional
a string representing the compression to use in the output file, allowed values are ‘gzip', ‘bz2', ‘xz', only used when the first argument is a filename
line_terminator : string, default '\n'
The newline character or character sequence to use in the output file
quoting : optional constant from csv module
defaults to csv.QUOTE_MINIMAL. If you have set a float_format then floats are converted to strings and thus csv.QUOTE_NONNUMERIC will treat them as non-numeric
quotechar : string (length 1), default ‘”'
character used to quote fields
doublequote : boolean, default True
Control quoting of quotechar inside a field
escapechar : string (length 1), default None
character used to escape sep and quotechar when appropriate
chunksize : int or None
rows to write at a time
tupleize_cols : boolean, default False
Deprecated since version 0.21.0: This argument will be removed and will always write each row of the multi-index as a separate row in the CSV file.
Write MultiIndex columns as a list of tuples (if True) or in the new, expanded format, where each MultiIndex column is a row in the CSV (if False).
date_format : string, default None
Format string for datetime objects
decimal: string, default ‘.'
Character recognized as decimal separator. E.g. use ‘,' for European data

以上这篇python的pandas工具包,保存.csv文件时不要表头的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python单元测试框架unittest简明使用实例

Python单元测试框架unittest简明使用实例

测试步骤 1. 导入unittest模块 import unittest 2. 编写测试的类继承unittest.TestCase class Tester(unittest.TestC...

Python在OpenCV里实现极坐标变换功能

Python在OpenCV里实现极坐标变换功能

在中学里学习过直角坐标系,也叫做笛卡尔坐标系,它是正交坐标系,不过也学习过极坐标系,这种坐标系比较适合大炮发射的场合。极坐标系的定义如下: 在 平面内取一个定点O, 叫极点,引一条射线O...

python+selenium开发环境搭建图文教程

python+selenium开发环境搭建图文教程

web 调试工具介绍和开发环境搭建 python与selenium开发环境搭建: 一、下载python软件:https://www.python.org/ 下载完后,进行安装,安装成功...

python使用多线程编写tcp客户端程序

python使用多线程编写tcp客户端程序

今天在网上找了半天,发现很多关于此题目的程序都只能接收数据,所以随便找了个程序研究了一下,然后做出一些修改 代码如下: from socket import * import thr...

使用python实现unix2dos和dos2unix命令的例子

由于工作电脑网络限制无法安装unix2dos和dos2unix命令转换文件,自己实现一个 直接上代码,保存为python文件如unix2dos.py然后使用命令 unix2dos.p...