當前位置: 首頁>>代碼示例>>Python>>正文


Python pandas.read_sas方法代碼示例

本文整理匯總了Python中pandas.read_sas方法的典型用法代碼示例。如果您正苦於以下問題:Python pandas.read_sas方法的具體用法?Python pandas.read_sas怎麽用?Python pandas.read_sas使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas的用法示例。


在下文中一共展示了pandas.read_sas方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_encoding_options

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def test_encoding_options(datapath):
    fname = datapath("io", "sas", "data", "test1.sas7bdat")
    df1 = pd.read_sas(fname)
    df2 = pd.read_sas(fname, encoding='utf-8')
    for col in df1.columns:
        try:
            df1[col] = df1[col].str.decode('utf-8')
        except AttributeError:
            pass
    tm.assert_frame_equal(df1, df2)

    from pandas.io.sas.sas7bdat import SAS7BDATReader
    rdr = SAS7BDATReader(fname, convert_header_text=False)
    df3 = rdr.read()
    rdr.close()
    for x, y in zip(df1.columns, df3.columns):
        assert(x == y.decode()) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_sas7bdat.py

示例2: test_encoding_options

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def test_encoding_options():
    dirpath = tm.get_data_path()
    fname = os.path.join(dirpath, "test1.sas7bdat")
    df1 = pd.read_sas(fname)
    df2 = pd.read_sas(fname, encoding='utf-8')
    for col in df1.columns:
        try:
            df1[col] = df1[col].str.decode('utf-8')
        except AttributeError:
            pass
    tm.assert_frame_equal(df1, df2)

    from pandas.io.sas.sas7bdat import SAS7BDATReader
    rdr = SAS7BDATReader(fname, convert_header_text=False)
    df3 = rdr.read()
    rdr.close()
    for x, y in zip(df1.columns, df3.columns):
        assert(x == y.decode()) 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:20,代碼來源:test_sas7bdat.py

示例3: read_sas

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def read_sas(
        cls,
        filepath_or_buffer,
        format=None,
        index=None,
        encoding=None,
        chunksize=None,
        iterator=False,
    ):  # pragma: no cover
        ErrorMessage.default_to_pandas("`read_sas`")
        return cls.from_pandas(
            pandas.read_sas(
                filepath_or_buffer,
                format=format,
                index=index,
                encoding=encoding,
                chunksize=chunksize,
                iterator=iterator,
            )
        ) 
開發者ID:modin-project,項目名稱:modin,代碼行數:22,代碼來源:io.py

示例4: test_from_iterator

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def test_from_iterator(self):
        for j in 0, 1:
            df0 = self.data[j]
            for k in self.test_ix[j]:
                fname = os.path.join(
                    self.dirpath, "test{k}.sas7bdat".format(k=k))
                rdr = pd.read_sas(fname, iterator=True, encoding='utf-8')
                df = rdr.read(2)
                tm.assert_frame_equal(df, df0.iloc[0:2, :])
                df = rdr.read(3)
                tm.assert_frame_equal(df, df0.iloc[2:5, :])
                rdr.close() 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:test_sas7bdat.py

示例5: get_format_extractor

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def get_format_extractor(self, stream, schema=None):
        return SASFormatExtractor(stream, schema, self.config)    


# Fix for the stream class provided by DSS
# Seek could be disabled by a one-liner like the following one but read_sas may seek forward
# self.stream.seek = types.MethodType(lambda self, _: False, self.stream) 
開發者ID:dataiku,項目名稱:dataiku-contrib,代碼行數:9,代碼來源:format.py

示例6: __init__

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def __init__(self, stream, schema, config):
        FormatExtractor.__init__(self, stream)
        
        chunksize = int(config.get("chunksize", "10000"))
        sas_format = config.get("sas_format", "sas7bdat")
        encoding = config.get("encoding", "latin_1")
        dump_to_file = config.get("dump_to_file", False)

        self.hasSchema = schema != None

        read_from = ForwardSeekStream(stream)

        if dump_to_file:
            dirname, _ = os.path.split(os.path.abspath(__file__))
            fullpath = os.path.join(dirname, 'dumped-%s.sas7bdat' % (time.time()))
            with open(fullpath, 'w+') as of:
                # Reading 500kb data everytime
                for data in iter((lambda:stream.read(500000)), b''):
                    of.write(data)
                
            read_from = fullpath

        self.iterator = pd.read_sas(read_from,
                                    format=sas_format,
                                    iterator=True,
                                    encoding=encoding,
                                    chunksize=chunksize)

        self.get_chunk() 
開發者ID:dataiku,項目名稱:dataiku-contrib,代碼行數:31,代碼來源:format.py

示例7: test_from_file

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def test_from_file(self):
        for j in 0, 1:
            df0 = self.data[j]
            for k in self.test_ix[j]:
                fname = os.path.join(
                    self.dirpath, "test{k}.sas7bdat".format(k=k))
                df = pd.read_sas(fname, encoding='utf-8')
                tm.assert_frame_equal(df, df0) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:10,代碼來源:test_sas7bdat.py

示例8: test_from_buffer

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def test_from_buffer(self):
        for j in 0, 1:
            df0 = self.data[j]
            for k in self.test_ix[j]:
                fname = os.path.join(
                    self.dirpath, "test{k}.sas7bdat".format(k=k))
                with open(fname, 'rb') as f:
                    byts = f.read()
                buf = io.BytesIO(byts)
                rdr = pd.read_sas(buf, format="sas7bdat",
                                  iterator=True, encoding='utf-8')
                df = rdr.read()
                tm.assert_frame_equal(df, df0, check_exact=False)
                rdr.close() 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:16,代碼來源:test_sas7bdat.py

示例9: test_path_pathlib

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def test_path_pathlib(self):
        from pathlib import Path
        for j in 0, 1:
            df0 = self.data[j]
            for k in self.test_ix[j]:
                fname = Path(os.path.join(
                    self.dirpath, "test{k}.sas7bdat".format(k=k)))
                df = pd.read_sas(fname, encoding='utf-8')
                tm.assert_frame_equal(df, df0) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:11,代碼來源:test_sas7bdat.py

示例10: test_path_localpath

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def test_path_localpath(self):
        from py.path import local as LocalPath
        for j in 0, 1:
            df0 = self.data[j]
            for k in self.test_ix[j]:
                fname = LocalPath(os.path.join(
                    self.dirpath, "test{k}.sas7bdat".format(k=k)))
                df = pd.read_sas(fname, encoding='utf-8')
                tm.assert_frame_equal(df, df0) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:11,代碼來源:test_sas7bdat.py

示例11: test_iterator_read_too_much

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def test_iterator_read_too_much(self):
        # github #14734
        k = self.test_ix[0][0]
        fname = os.path.join(self.dirpath, "test{k}.sas7bdat".format(k=k))
        rdr = pd.read_sas(fname, format="sas7bdat",
                          iterator=True, encoding='utf-8')
        d1 = rdr.read(rdr.row_count + 20)
        rdr.close()

        rdr = pd.read_sas(fname, iterator=True, encoding="utf-8")
        d2 = rdr.read(rdr.row_count + 20)
        tm.assert_frame_equal(d1, d2)
        rdr.close() 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:15,代碼來源:test_sas7bdat.py

示例12: test_productsales

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def test_productsales(datapath):
    fname = datapath("io", "sas", "data", "productsales.sas7bdat")
    df = pd.read_sas(fname, encoding='utf-8')
    fname = datapath("io", "sas", "data", "productsales.csv")
    df0 = pd.read_csv(fname, parse_dates=['MONTH'])
    vn = ["ACTUAL", "PREDICT", "QUARTER", "YEAR"]
    df0[vn] = df0[vn].astype(np.float64)
    tm.assert_frame_equal(df, df0) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:10,代碼來源:test_sas7bdat.py

示例13: test_12659

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def test_12659(datapath):
    fname = datapath("io", "sas", "data", "test_12659.sas7bdat")
    df = pd.read_sas(fname)
    fname = datapath("io", "sas", "data", "test_12659.csv")
    df0 = pd.read_csv(fname)
    df0 = df0.astype(np.float64)
    tm.assert_frame_equal(df, df0) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:9,代碼來源:test_sas7bdat.py

示例14: test_airline

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def test_airline(datapath):
    fname = datapath("io", "sas", "data", "airline.sas7bdat")
    df = pd.read_sas(fname)
    fname = datapath("io", "sas", "data", "airline.csv")
    df0 = pd.read_csv(fname)
    df0 = df0.astype(np.float64)
    tm.assert_frame_equal(df, df0, check_exact=False) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:9,代碼來源:test_sas7bdat.py

示例15: test_compact_numerical_values

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import read_sas [as 別名]
def test_compact_numerical_values(datapath):
    # Regression test for #21616
    fname = datapath("io", "sas", "data", "cars.sas7bdat")
    df = pd.read_sas(fname, encoding='latin-1')
    # The two columns CYL and WGT in cars.sas7bdat have column
    # width < 8 and only contain integral values.
    # Test that pandas doesn't corrupt the numbers by adding
    # decimals.
    result = df['WGT']
    expected = df['WGT'].round()
    tm.assert_series_equal(result, expected, check_exact=True)
    result = df['CYL']
    expected = df['CYL'].round()
    tm.assert_series_equal(result, expected, check_exact=True) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:16,代碼來源:test_sas7bdat.py


注:本文中的pandas.read_sas方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。