===============================================================================0
>>> with open("../read.py", "rt", encoding="utf8") as fp: exec(fp.read())
测试csv参数
===============================================================================1
基本用法
>>> df = read("../data/iris.csv")
>>> print(df.head())
===============================================================================2
读取其他分隔符
>>> df = read("../data/iris.csv", textfileparamsdict={"sep": ","})
>>> print(df.head())
===============================================================================3
不指定任何行作为列名
>>> df = read("../data/iris.csv", textfileparamsdict={"header": None})
>>> print(df.head())
===============================================================================4
指定列名
>>> df = read("../data/iris.csv", textfileparamsdict={"names": ["sepal_length", "sepal_width", "petal_length", "petal_width", "species"]})
>>> print(df.head())
===============================================================================5
指定索引
>>> df = read("../data/iris.csv", textfileparamsdict={"index_col": 1})
>>> print(df.head())
===============================================================================6
指定读取的列名
>>> df = read("../data/iris.csv", textfileparamsdict={"usecols": ["Sepal.Length", "Sepal.Width", "Species"]})
>>> print(df.head())
===============================================================================7
指定读取的文件行数
>>> df = read("../data/iris.csv", textfileparamsdict={"names": ["sepal_length", "sepal_width", "petal_length", "petal_width", "species"], "nrows": 3})
>>> print(df.head())
===============================================================================8
测试excel文件读取
===============================================================================9
将第一列作为行名
>>> df = read("../data/iris.xlsx", excelfileparamsdict={"index_col": 0})
>>> print(df.head())
不将第一列作为行名
>>> df = read("../data/iris.xlsx")
>>> print(df.head())
不将第一行作为列名
>>> df = read("../data/iris.xlsx", excelfileparamsdict={"header": None})
>>> print(df.head())
将第一列作为行名且指定列名
>>> df = read("../data/iris.xlsx", excelfileparamsdict={"index_col": 0, "names": ["v1", "v2", "v3", "v4", "v5"]})
>>> print(df.head())
指定要读取的列
>>> df = read("../data/iris.xlsx", excelfileparamsdict={"usecols": ["Sepal.Length", "Sepal.Width", "Species"], "index_col": 0})
>>> print(df.head())
指定读取的行数
>>> df = read("../data/iris.xlsx", excelfileparamsdict={"usecols": ["Sepal.Length", "Sepal.Width", "Species"], "nrows": 50})
>>> print(df.head())
读取xls文件
>>> df = read("../data/womenexport.xls")
>>> print(df.head())
===============================================================================10
测试pkl参数
===============================================================================11
>>> df = read("../data/iris.pkl")
>>> print(df.head())
===============================================================================12
测试dta参数
>>> df = read("../data/auto.dta")
>>> print(df.head())
===============================================================================13
测试xpt参数
>>> df = read("../data/hh.xpt")
>>> print(df.head())
===============================================================================14
测试sav参数
>>> df = read("../data/iris.sav")
>>> print(df.head())
===============================================================================15
