【338】Pandas.DataFrame

Ref: Pandas Tutorial: DataFrames in Python

Ref: pandas.DataFrame

class pandas. DataFrame (data=None, index=None, columns=None, dtype=None, copy=False)
Parameters:

data : numpy ndarray (structured or homogeneous), dict, or DataFrame

Dict can contain Series, arrays, constants, or list-like objects

Changed in version 0.23.0: If data is a dict, argument order is maintained for Python 3.6 and later.

index : Index or array-like

Index to use for resulting frame. Will default to RangeIndex if no indexing information part of input data and no index provided

columns : Index or array-like

Column labels to use for resulting frame. Will default to RangeIndex (0, 1, 2, …, n) if no column labels are provided

dtype : dtype, default None

Data type to force. Only a single dtype is allowed. If None, infer

copy : boolean, default False

Copy data from inputs. Only affects DataFrame / 2d ndarray input

data[1:,0] means the first column, data[0,1:] means the first row.

>>> import numpy as np
>>> import pandas as pd
>>> data = np.array([
	['','Col1','Col2'],
	['Row1',1,2],
	['Row2',3,4]
	])
>>> print(pd.DataFrame(data=data[1:,1:],
		       index=data[1:,0],
		       columns=data[0,1:]))
     Col1 Col2
Row1    1    2
Row2    3    4

猜你喜欢

转载自www.cnblogs.com/alex-bn-lee/p/9951877.html
今日推荐