pandas(一)

pandas.io

1.概述,主要从txt,json,pkl,csv,excel中读取数据,读取的数据最终转化为pandas.core.frame.DataFrame类型的df

先来看总的api

from pandas.io.clipboards import read_clipboard #读剪切板
from pandas.io.excel import ExcelFile, ExcelWriter, read_excel #读excel
from pandas.io.feather_format import read_feather
from pandas.io.gbq import read_gbq
from pandas.io.html import read_html
from pandas.io.json import read_json
from pandas.io.packers import read_msgpack, to_msgpack
from pandas.io.parquet import read_parquet
from pandas.io.parsers import read_csv, read_fwf, read_table
from pandas.io.pickle import read_pickle, to_pickle
from pandas.io.pytables import HDFStore, read_hdf
from pandas.io.sas import read_sas
from pandas.io.spss import read_spss
from pandas.io.sql import read_sql, read_sql_query, read_sql_table
from pandas.io.stata import read_stata

io的api里主要包含了读取操作,写入操作主要在pandas.core.frame.DataFrame

2.一个为操作pkl文件的demo

import pandas as pd

original_df = pd.DataFrame({"foo": range(5), "bar": range(5, 10)})

pd.to_pickle(original_df, "~/work/data/dummy.pkl")

df = pd.read_pickle("~/work/data/dummy.pkl")

如果df想写入为csv或其他格式可以调用df.to_csv

相关推荐