小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

DataFrame的存儲

 powerbaby 2016-03-14

Pandas中的DataFrame數(shù)據(jù)既可以存儲在SQL數(shù)據(jù)庫中,也可以直接存儲在CSV文件中。

數(shù)據(jù)庫

1. dataframe.to_sql()函數(shù)將DataFrame數(shù)據(jù)存儲到數(shù)據(jù)庫中。

name :數(shù)據(jù)表的名稱, string, Name of SQL table

con : 數(shù)據(jù)庫的鏈接,SQLAlchemy engine or DBAPI2 connection (legacy mode)

if_exists : 如果SQL表已經(jīng)存在的處理方式,{‘fail’, ‘replace’, ‘a(chǎn)ppend’}, default ‘fail’

 取消存儲, fail: If table exists, do nothing.

 替換SQL表,replace: If table exists, drop it, recreate it, and insert data.

 附加在SQL表后,append: If table exists, insert data. Create if does not exist.

index : 是否將行標簽存入SQL表,boolean, default TrueWrite DataFrame index as a column.

index_label : 如果存儲行標簽,指定該列的名稱,string or sequence, default None, Column label for index column(s). 

2. pandas.read_sql()函數(shù)將SQL表讀入DataFrame。

sql : 要讀取的SQL表,string, database table name.

con : 與數(shù)據(jù)庫的鏈接,SQLAlchemy engine

index_col : 指定用于行標簽的列,string, optional, column name to use as index for the returned DataFrame object.

CSV文件

1. dataframe.to_csv()函數(shù)將DataFrame數(shù)據(jù)存儲在指定的csv文件中。該函數(shù)常用的參數(shù)有

columns : 指定需要存儲的列,Columns to write

header : 是否把列的名字寫入CSV文件, boolean, default True. Write out column names. If a list of string is given it is assumed to be aliases for the column names

index : 是否把index寫入CSV文件,boolean, default True.Write row labels (index)

index_label : 如果將index寫入CSV文件,那么給出index列的標簽(列的名字),string or sequence, or False, default None. 

2. pandas.read_csv()函數(shù)將CSV文件中的數(shù)據(jù)讀入DataFrame。

header : CSV文件的列名所在的行, int, list of ints.  Row number(s) to use as the column names, and the start of the data. Defaults to 0 if no names passed, otherwise None. 

index_col : 指定行標簽所在的列,int or sequence or False, default None. Column to use as the row labels of the DataFrame. 

names : 列的名稱,array-like. List of column names to use. 

總結(jié):

相同點:?

1. 存儲時,CSV和SQL都默認存儲行標簽(index),因此需要指定存儲行標簽列的名字,index_label。

2. 讀取時,CSV和SQL都需要指定哪一列是行標簽(index)列,index_col,不同的是CSV是通過列的序號指定,SQL是通過列的名字指定。?

不同點:

1. SQL一定會存儲列標簽,CSV可以存儲列標簽也可以不存儲列標簽。?

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多