Convert structured or record ndarray to DataFrame. Creates a DataFrame object from a structured ndarray, or iterable of tuples or dicts. Parameters ---------- data : structured ndarray, iterable of tuples or dicts Structured input data.
(
cls,
data,
index=None,
exclude=None,
columns=None,
coerce_float: bool = False,
nrows: int | None = None,
)
| 2237 | |
| 2238 | @classmethod |
| 2239 | def from_records( |
| 2240 | cls, |
| 2241 | data, |
| 2242 | index=None, |
| 2243 | exclude=None, |
| 2244 | columns=None, |
| 2245 | coerce_float: bool = False, |
| 2246 | nrows: int | None = None, |
| 2247 | ) -> DataFrame: |
| 2248 | """ |
| 2249 | Convert structured or record ndarray to DataFrame. |
| 2250 | |
| 2251 | Creates a DataFrame object from a structured ndarray, or iterable of |
| 2252 | tuples or dicts. |
| 2253 | |
| 2254 | Parameters |
| 2255 | ---------- |
| 2256 | data : structured ndarray, iterable of tuples or dicts |
| 2257 | Structured input data. |
| 2258 | index : str, list of fields, array-like |
| 2259 | Field of array to use as the index, alternately a specific set of |
| 2260 | input labels to use. |
| 2261 | exclude : sequence, default None |
| 2262 | Columns or fields to exclude. |
| 2263 | columns : sequence, default None |
| 2264 | Column names to use. If the passed data do not have names |
| 2265 | associated with them, this argument provides names for the |
| 2266 | columns. Otherwise, this argument indicates the order of the columns |
| 2267 | in the result (any names not found in the data will become all-NA |
| 2268 | columns) and limits the data to these columns if not all column names |
| 2269 | are provided. |
| 2270 | coerce_float : bool, default False |
| 2271 | Attempt to convert values of non-string, non-numeric objects (like |
| 2272 | decimal.Decimal) to floating point, useful for SQL result sets. |
| 2273 | nrows : int, default None |
| 2274 | Number of rows to read if data is an iterator. |
| 2275 | |
| 2276 | Returns |
| 2277 | ------- |
| 2278 | DataFrame |
| 2279 | |
| 2280 | See Also |
| 2281 | -------- |
| 2282 | DataFrame.from_dict : DataFrame from dict of array-like or dicts. |
| 2283 | DataFrame : DataFrame object creation using constructor. |
| 2284 | |
| 2285 | Examples |
| 2286 | -------- |
| 2287 | Data can be provided as a structured ndarray: |
| 2288 | |
| 2289 | >>> data = np.array( |
| 2290 | ... [(3, "a"), (2, "b"), (1, "c"), (0, "d")], |
| 2291 | ... dtype=[("col_1", "i4"), ("col_2", "U1")], |
| 2292 | ... ) |
| 2293 | >>> pd.DataFrame.from_records(data) |
| 2294 | col_1 col_2 |
| 2295 | 0 3 a |
| 2296 | 1 2 b |