机器学习时pandas里面常用的函数

1.value_counts()

表示统计不同属性出现的次数。

机器学习时pandas里面常用的函数

2.read_csv()读取数据,head()读取数据的前五行

机器学习时pandas里面常用的函数

3.info(),查看表格的相应数据信息,看有不有缺失值的情况。

机器学习时pandas里面常用的函数

4.describe(),观察常用统计量观察其分布

机器学习时pandas里面常用的函数

5、Using the get_dummies will create a new column for every unique string in a certain column:使用get_dummies进行one-hot编码

机器学习时pandas里面常用的函数

6.DataFrame(),自己个人的理解就是把数据做成表格的形式。

DataFrame(data=Noneindex=Nonecolumns=Nonedtype=Nonecopy=False)

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

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

index : Index or array-like

Index to use for resulting frame. Will default to np.arange(n) 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 np.arange(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


[source]

Constructing DataFrame from a dictionary.

>>> d = {'col1': [1, 2], 'col2': [3, 4]}
>>> df = pd.DataFrame(data=d) 表格存放的内容
>>> df
   col1  col2
0     1     3
1     2     4

Notice that the inferred dtype is int64.

>>> df.dtypes
col1    int64
col2    int64
dtype: object

To enforce a single dtype:

>>> df = pd.DataFrame(data=d, dtype=np.int8)  dtype就是定义数据的类型
>>> df.dtypes
col1    int8
col2    int8
dtype: object

Constructing DataFrame from numpy ndarray:

>>> df2 = pd.DataFrame(np.random.randint(low=0, high=10, size=(5, 5)),
...                    columns=['a', 'b', 'c', 'd', 'e'])  columns就是加一个表头
>>> df2
    a   b   c   d   e
0   2   8   8   3   4
1   4   2   9   0   9
2   1   0   7   8   0
3   5   1   7   1   3
4   6   0   2   4   2
7.concat()合并内容 ,详细可以参考http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html
concat(objsaxis=0join='outer'join_axes=Noneignore_index=Falsekeys=Nonelevels=Nonenames=Noneverify_integrity=Falsecopy=True)
默认的方式是行合并,列的方式合并为axis =1

在合并的时候,可能会出现以下的错误

机器学习时pandas里面常用的函数

解决的办法:就是给的数据一定是要以列表的形式

机器学习时pandas里面常用的函数

8.to_csv()

把处理后的数据保存在csv的文件里面。

机器学习时pandas里面常用的函数

9.drop():用于删除数据,并返回删除后的数据

机器学习时pandas里面常用的函数

inplace=True是直接对原数据进行操作。False将不改变原来的dataFrame,而将结果生成在一个新的dataFrame中