读取和写入文件
读取 | 写入 |
---|---|
read_csv | to_csv |
read_excel | to_excel |
read_hdf | to_hdf |
read_sql | to_sql |
read_json | to_json |
read_msgpack (experimental) | to_msgpack (experimental) |
read_html | to_html |
read_gbq(experimental) | to_gbq (experimental) |
read_stata | to_stata |
read_sas | ro_sas |
read_clipboard | to_clipboard |
read_pickle | to_pickle//速度比csv快 |
保存文件
1 | submission = pd.DataFrame({ 'PassengerId': test_df['PassengerId'],'Survived': predictions }) |
流处理
当读取大文件的时候,通过chunksize
可以分批次读取:
1 | # 使用类似迭代器的方式 |
是否为空
1 | pd.isnull(obj) |
转成DF数据框
1 | DataFrame(data, |
查看索引和列名
1 | DataFrame.columns |
列属性和索引重排
1 | DataFrame.reindex([columns=['col1','col2','col3'...]) |
重命名索引和轴
1 | data.rename(index=str.title,columns=str.upper) |
DF选取子集
针对S
1 | obj[['a','b','c'...]] |
针对DF
1 | #选择多列 |
排序和排名
1 | #默认根据index排序,axis = 1 则根据columns排序 |
成员 、唯一值、成员资格
1 | obj.unique() |
透视表
1 | table = df.pivot_table(values=["Price","Quantity"], |