Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.from_records#

classmethodDataFrame.from_records(data,index=None,exclude=None,columns=None,coerce_float=False,nrows=None)[source]#

Convert structured or record ndarray to DataFrame.

Creates a DataFrame object from a structured ndarray, sequence oftuples or dicts, or DataFrame.

Parameters:
datastructured ndarray, sequence of tuples or dicts, or DataFrame

Structured input data.

Deprecated since version 2.1.0:Passing a DataFrame is deprecated.

indexstr, list of fields, array-like

Field of array to use as the index, alternately a specific set ofinput labels to use.

excludesequence, default None

Columns or fields to exclude.

columnssequence, default None

Column names to use. If the passed data do not have namesassociated with them, this argument provides names for thecolumns. Otherwise this argument indicates the order of the columnsin the result (any names not found in the data will become all-NAcolumns).

coerce_floatbool, default False

Attempt to convert values of non-string, non-numeric objects (likedecimal.Decimal) to floating point, useful for SQL result sets.

nrowsint, default None

Number of rows to read if data is an iterator.

Returns:
DataFrame

See also

DataFrame.from_dict

DataFrame from dict of array-like or dicts.

DataFrame

DataFrame object creation using constructor.

Examples

Data can be provided as a structured ndarray:

>>>data=np.array([(3,'a'),(2,'b'),(1,'c'),(0,'d')],...dtype=[('col_1','i4'),('col_2','U1')])>>>pd.DataFrame.from_records(data)   col_1 col_20      3     a1      2     b2      1     c3      0     d

Data can be provided as a list of dicts:

>>>data=[{'col_1':3,'col_2':'a'},...{'col_1':2,'col_2':'b'},...{'col_1':1,'col_2':'c'},...{'col_1':0,'col_2':'d'}]>>>pd.DataFrame.from_records(data)   col_1 col_20      3     a1      2     b2      1     c3      0     d

Data can be provided as a list of tuples with corresponding columns:

>>>data=[(3,'a'),(2,'b'),(1,'c'),(0,'d')]>>>pd.DataFrame.from_records(data,columns=['col_1','col_2'])   col_1 col_20      3     a1      2     b2      1     c3      0     d

[8]ページ先頭

©2009-2025 Movatter.jp