官方文档:
Format Type | Data Description | Reader | Writer |
---|---|---|---|
text | CSV | read_csv | to_csv |
text | JSON | read_json | to_json |
text | HTML | read_html | to_html |
text | Local clipboard | read_clipboard | to_clipboard |
binary | MS Excel | read_excel | to_excel |
binary | HDF5 Format | read_hdf | to_hdf |
binary | Feather Format | read_feather | to_feather |
binary | Msgpack | read_msgpack | to_msgpack |
binary | Stata | read_stata | to_stata |
binary | SAS | read_sas | |
binary | Python Pickle Format | read_pickle | to_pickle |
SQL | SQL | read_sql | to_sql |
SQL | Google Big Query | read_gbq | to_gbq |
其中重点想说一说read_clipboard()和read_csv()这两个典型的例子,前者从粘贴板读取和写入,在实际应用中真的是非常的方便,有点开始佩服那些开发者的脑洞了。
后者是最常用的。源码如下:(read_csv和to_csv类似)
1 def to_csv(self, path_or_buf=None, sep=",", na_rep=‘‘, float_format=None, 2 columns=None, header=True, index=True, index_label=None, 3 mode=‘w‘, encoding=None, compression=None, quoting=None, 4 quotechar=‘"‘, line_terminator=‘\n‘, chunksize=None, 5 tupleize_cols=None, date_format=None, doublequote=True, 6 escapechar=None, decimal=‘.‘): 7 r"""Write DataFrame to a comma-separated values (csv) file