r"""Read a delimiter-separated file into a data frame. Parameters ---------- directory : str Full directory specification. filename : str Name of the file to read, excluding the ``extension``. extension : str File name extension, e.g., ``csv``. separa
(directory, filename, extension, separator,
index_col=None, squeeze=False)
| 133 | # |
| 134 | |
| 135 | def read_frame(directory, filename, extension, separator, |
| 136 | index_col=None, squeeze=False): |
| 137 | r"""Read a delimiter-separated file into a data frame. |
| 138 | |
| 139 | Parameters |
| 140 | ---------- |
| 141 | directory : str |
| 142 | Full directory specification. |
| 143 | filename : str |
| 144 | Name of the file to read, excluding the ``extension``. |
| 145 | extension : str |
| 146 | File name extension, e.g., ``csv``. |
| 147 | separator : str |
| 148 | The delimiter between fields in the file. |
| 149 | index_col : str, optional |
| 150 | Column to use as the row labels in the dataframe. |
| 151 | squeeze : bool, optional |
| 152 | If the data contains only one column, then return a pandas Series. |
| 153 | |
| 154 | Returns |
| 155 | ------- |
| 156 | df : pandas.DataFrame |
| 157 | The pandas dataframe loaded from the file location. If the file |
| 158 | cannot be located, then ``None`` is returned. |
| 159 | |
| 160 | """ |
| 161 | file_only = PSEP.join([filename, extension]) |
| 162 | file_all = SSEP.join([directory, file_only]) |
| 163 | logger.info("Loading data from %s", file_all) |
| 164 | try: |
| 165 | df = pd.read_csv(file_all, sep=separator, index_col=index_col, |
| 166 | squeeze=squeeze, low_memory=False) |
| 167 | except: |
| 168 | df = pd.DataFrame() |
| 169 | logger.info("Could not find or access %s", file_all) |
| 170 | return df |
| 171 | |
| 172 | |
| 173 | # |
no outgoing calls
no test coverage detected