How to use the pyreadstat.read_por function in pyreadstat

To help you get started, we’ve selected a few pyreadstat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Roche / pyreadstat / tests / test_basic.py View on Github external
def test_por(self):
        df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"))
        # dates, datetimes and timestamps are not translated but stay as integers, let's just drop them
        df_pandas_por = self.df_pandas.drop(labels=["dtime", "mydate", "mytime"], axis=1)
        df.columns = [x.lower() for x in df.columns]
        df = df.drop(labels=["dtime", "mydate", "mytime"], axis=1)
        self.assertTrue(df.equals(df_pandas_por))
        self.assertTrue(meta.number_columns == len(self.df_pandas.columns))
        self.assertTrue(meta.number_rows == len(df_pandas_por))
        self.assertTrue(len(meta.notes) > 0)
github Roche / pyreadstat / tests / test_basic.py View on Github external
def test_por_formatted(self):
        df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), apply_value_formats=True, formats_as_category=True)
        # dates, datetimes and timestamps are not translated but stay as integers, let's just drop them
        df_pandas_por = self.df_pandas_formatted.drop(labels=["dtime", "mydate", "mytime"], axis=1)
        df.columns = [x.lower() for x in df.columns]
        df = df.drop(labels=["dtime", "mydate", "mytime"], axis=1)
        self.assertTrue(df.equals(df_pandas_por))
        self.assertTrue(meta.number_columns == len(self.df_pandas_formatted.columns))
        self.assertTrue(meta.number_rows == len(df_pandas_por))
        self.assertTrue(len(meta.notes) > 0)
github Roche / pyreadstat / tests / test_basic.py View on Github external
def test_por_nodates(self):
        df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), disable_datetime_conversion=True)
        df.columns = [x.lower() for x in df.columns]
        self.assertTrue(df.equals(self.df_nodates_spss))
github Roche / pyreadstat / tests / test_basic.py View on Github external
def test_por_usecols(self):
        df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"),  usecols=["MYNUM"])
        df_pandas_por = self.df_pandas[["mynum"]]
        df.columns = [x.lower() for x in df.columns]
        self.assertTrue(df.equals(df_pandas_por))
        self.assertTrue(meta.number_columns == len(df_pandas_por.columns.values.tolist()))
github Roche / pyreadstat / tests / test_basic.py View on Github external
def test_por_metaonly(self):

        df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"))
        df2, meta2 = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), metadataonly=True)
        self.assertTrue(df2.empty)
        self.assertTrue(meta.number_columns == meta2.number_columns)
        self.assertTrue(meta2.number_rows is None)
        self.assertTrue(meta.column_names == meta2.column_names)
        self.assertTrue(meta.column_labels == meta2.column_labels)
        self.assertTrue(len(meta2.notes) > 0)
github Roche / pyreadstat / tests / test_basic.py View on Github external
def test_por_metaonly(self):

        df, meta = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"))
        df2, meta2 = pyreadstat.read_por(os.path.join(self.basic_data_folder, "sample.por"), metadataonly=True)
        self.assertTrue(df2.empty)
        self.assertTrue(meta.number_columns == meta2.number_columns)
        self.assertTrue(meta2.number_rows is None)
        self.assertTrue(meta.column_names == meta2.column_names)
        self.assertTrue(meta.column_labels == meta2.column_labels)
        self.assertTrue(len(meta2.notes) > 0)

pyreadstat

Reads and Writes SAS, SPSS and Stata files into/from pandas data frames.

Apache-2.0
Latest version published 2 months ago

Package Health Score

82 / 100
Full package analysis

Similar packages