read_csv
# 函数原型
pandas
.
read_csv
(
filepath_or_buffer
,
sep
=
', '
,
delimiter
=
None
,
header
=
'infer'
,
names
=
None
,
index_col
=
None
,
usecols
=
None
,
squeeze
=
False
,
prefix
=
None
,
mangle_dupe_cols
=
True
,
dtype
=
None
,
engine
=
None
,
converters
=
None
,
true_values
=
None
,
false_values
=
None
,
skipinitialspace
=
False
,
skiprows
=
None
,
skipfooter
=
0
,
nrows
=
None
,
na_values
=
None
,
keep_default_na
=
True
,
na_filter
=
True
,
verbose
=
False
,
skip_blank_lines
=
True
,
parse_dates
=
False
,
infer_datetime_format
=
False
,
keep_date_col
=
False
,
date_parser
=
None
,
dayfirst
=
False
,
iterator
=
False
,
chunksize
=
None
,
compression
=
'infer'
,
thousands
=
None
,
decimal
=
b
'.'
,
lineterminator
=
None
,
quotechar
=
'"'
,
quoting
=
0
,
doublequote
=
True
,
escapechar
=
None
,
comment
=
None
,
encoding
=
None
,
dialect
=
None
,
tupleize_cols
=
None
,
error_bad_lines
=
True
,
warn_bad_lines
=
True
,
delim_whitespace
=
False
,
low_memory
=
True
,
memory_map
=
False
,
float_precision
=
None
)
常用参数
filepath_or_buffer
:通常为文件路径
sep
:分隔符
header
:列名所在的行号。 默认为0(第一行),如果没有则设置为
None
names
:用于结果的列名列表,对各列重命名,即添加表头。如数据有表头,但想用新的表头,可以设置
header=0,names=['a','b']
实现表头定制。
index_col
:用作行名(即行索引)的列编号或者列名。默认为
None
usecols
:需要读取的列。可设置为
usecols=[1,2]
或
usercols=['a','b']
encoding
:编码格式。【通常应该手动设置为
"utf8"
】
to_csv
# 函数原型
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
=
'.'
)
常用参数
path_or_buf
:通常为文件路径
sep
:分隔符
columns
:需要写的列。默认为全部。
header
:是否保存列名。布尔值或者字符串列表。默认为
TRUE
,即保存列名。如果参数为字符串列表,则将列名一一替换成字符串并保存。
index
:是否保存行名,布尔值。默认为
TRUE
encoding
:编码格式【通常应该手动设置为
"utf8"
】
参考文献
1. http://www.voidcn.com/article/p-bnoadxrc-bqt.html