A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

安装数据分析库
可以通过pip,也可以通过conda来安装
安装命令: pip install / conda install
pip install numpy
pip install scipy
pip install pandas
pip install matplotlib
pip install -U nltk
pip install -U python-igrahp
pip install -U scikit-learn

conda文档
https://conda.io/docs/user-guide/tasks/manage-environments.html

[root@master ~]# conda install numpy
[root@master ~]# conda install scipy
[root@master ~]# conda install pandas
[root@master ~]# conda install matplotlib
[root@master ~]# conda install nltk
[root@master ~]# conda install -c marufr python-igraph=0.7.1.post6
[root@master ~]# conda install scikit-learn

windows上scipy使用pip安装可能会报错,windows上不能直接通过pip安装scipy
C:\Users\iversondong>pip install wheel
如果有安装numpy可以卸载:
C:\Users\iversondong>pip uninstall numpy

numpy / scipy / pandas 使用whl 文件进行安装:下载相对应的版本
https://pypi.python.org/pypi/numpy
https://pypi.python.org/pypi/scipy
https://pypi.python.org/pypi/pandas

C:\Users\iversondong\Desktop\新建文件夹\软件安装包\windows 的目录
2017/10/17 12:46 534,742,736 Anaconda3-5.0.0-Windows-x86_64.exe
2016/11/07 03:30 1,595,408 get-pip.py
2017/10/17 13:43 12,953,934 numpy-1.13.3-cp27-none-win_amd64.whl
2017/10/17 13:44 9,014,536 pandas-0.21.0rc1-cp27-cp27m-win_amd64.whl
2017/10/17 11:52 19,238,912 python-2.7.14rc1.amd64.msi
2017/10/17 13:42 30,654,098 scipy-1.0.0rc1-cp27-none-win_amd64.whl



python数据分析库简单使用
numpy:
>>> import numpy as np
>>> np.arange(10)
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> a = np.arange(10)
>>> a ** 2
array([ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81])
>>>

scipy:
>>> import numpy as np
>>> from scipy import linalg
>>> A = np.array([[1,2],[3,4]])
>>> A
array([[1, 2],
[3, 4]])
>>> linalg.det(A)
-2.0

pandas:
>>> import pandas as pd
>>> import numpy as np
>>> s = pd.Series([1,3,5,np.nan,6,8])
>>> s
0 1.0
1 3.0
2 5.0
3 NaN
4 6.0
5 8.0
dtype: float64

>>> dates = pd.date_range('20171010', periods=6)
>>> dates
DatetimeIndex(['2017-10-10', '2017-10-11', '2017-10-12', '2017-10-13',
'2017-10-14', '2017-10-15'],
dtype='datetime64[ns]', freq='D')
>>>

>>> df = pd.DataFrame(np.random.randn(6,4), index=dates,columns=list('ABCD'))
>>> df
A B C D
2017-10-10 -1.392238 1.702931 -0.316173 0.870619
2017-10-11 0.286415 -0.295344 -0.771379 0.152240
2017-10-12 -0.981891 -1.479419 0.736965 -0.825239
2017-10-13 0.819520 -0.064909 -0.537274 0.849306
2017-10-14 -0.096912 0.012100 -1.159226 -0.284764
2017-10-15 -0.216369 -0.221942 -0.977730 -2.283849

>>> df.head()
A B C D
2017-10-10 -1.392238 1.702931 -0.316173 0.870619
2017-10-11 0.286415 -0.295344 -0.771379 0.152240
2017-10-12 -0.981891 -1.479419 0.736965 -0.825239
2017-10-13 0.819520 -0.064909 -0.537274 0.849306
2017-10-14 -0.096912 0.012100 -1.159226 -0.284764
>>> df.head(1)
A B C D
2017-10-10 -1.392238 1.702931 -0.316173 0.870619
>>> df.tail()
A B C D
2017-10-11 0.286415 -0.295344 -0.771379 0.152240
2017-10-12 -0.981891 -1.479419 0.736965 -0.825239
2017-10-13 0.819520 -0.064909 -0.537274 0.849306
2017-10-14 -0.096912 0.012100 -1.159226 -0.284764
2017-10-15 -0.216369 -0.221942 -0.977730 -2.283849
>>> df.tail(1)
A B C D
2017-10-15 -0.216369 -0.221942 -0.97773 -2.283849

>>> df.describe()
A B C D
count 6.000000 6.000000 6.000000 6.000000
mean -0.145039 0.051830 -0.217846 -0.365617
std 1.193140 0.878258 0.428225 0.450481
min -1.353531 -1.036063 -0.710604 -1.137336
25% -0.838167 -0.595775 -0.465619 -0.503953
50% -0.408743 0.071709 -0.312854 -0.297031
75% 0.097002 0.552613 -0.042156 -0.062045
max 2.016505 1.308982 0.497699 0.094337

>>> df.T
2017-10-10 2017-10-11 2017-10-12 2017-10-13 2017-10-14 2017-10-15
A -1.392238 0.286415 -0.981891 0.819520 -0.096912 -0.216369
B 1.702931 -0.295344 -1.479419 -0.064909 0.012100 -0.221942
C -0.316173 -0.771379 0.736965 -0.537274 -1.159226 -0.977730
D 0.870619 0.152240 -0.825239 0.849306 -0.284764 -2.283849
>>> df.sort_values(by='D')
A B C D
2017-10-15 -0.216369 -0.221942 -0.977730 -2.283849
2017-10-12 -0.981891 -1.479419 0.736965 -0.825239
2017-10-14 -0.096912 0.012100 -1.159226 -0.284764
2017-10-11 0.286415 -0.295344 -0.771379 0.152240
2017-10-13 0.819520 -0.064909 -0.537274 0.849306
2017-10-10 -1.392238 1.702931 -0.316173 0.870619
>>>


%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1,2,3])
plt.ylabel('some numbers')
plt.show()

【转载】原文地址:https://blog.csdn.net/eduandu/article/details/80920640


3 个回复

正序浏览
赞一个
回复 使用道具 举报
回复 使用道具 举报
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马