每次启动IPython Notebook时,我运行的第一个命令是
%matplotlib inline
Run Code Online (Sandbox Code Playgroud)
有没有办法改变我的配置文件,以便在我启动IPython时,它会自动进入这种模式?
我想为1,2和3 weight_cat值绘制三个箱图(这些是它唯一的不同值).这些箱图应显示重量类别(weight_cat)的依赖性高度.
所以我有这样一个数据帧:
print data.head(5)
Height Weight weight_cat
Index
1 65.78331 112.9925 1
2 71.51521 136.4873 2
3 69.39874 153.0269 3
4 68.21660 142.3354 2
5 67.78781 144.2971 2
Run Code Online (Sandbox Code Playgroud)
下面的代码终于吃掉了我的所有内存.这是不正常的,我相信:
Seaborn.boxplot(x="Height", y="weight_cat", data=data)
Run Code Online (Sandbox Code Playgroud)
这有什么不对?这是手册的链接.数据帧的形状是(25000,4).这是csv文件的链接.
这是你如何获得相同的数据:
data = pd.read_csv('weights_heights.csv', index_col='Index')
def weight_category(weight):
newWeight = weight
if newWeight < 120:
return 1
if newWeight >= 150:
return 3
else:
return 2
data['weight_cat'] = data['Weight'].apply(weight_category)
Run Code Online (Sandbox Code Playgroud) 我有一堆股票数据,我正在尝试构建一个数据框,从相关矩阵中获取前两个和底部的股票,以及它们的实际相关性。
假设矩阵corr如下所示:
A B C D E
A 1.00 0.65 0.31 0.94 0.55
B 0.87 1.00 0.96 0.67 0.41
C 0.95 0.88 1.00 0.72 0.69
D 0.64 0.84 0.99 1.00 0.78
E 0.71 0.62 0.89 0.32 1.00
Run Code Online (Sandbox Code Playgroud)
我想要做的是能够返回股票 A、B、C、D 和 E 的最佳两只和最不相关的股票及其相关性,同时降低每只股票与自身之间明显的 1.00 相关性。
生成的数据框,或任何最容易显示的数据框如下所示:
Stock 1st 1st_Val 2nd 2nd_Val Last Last_Val
A D 0.94 B 0.65 C 0.31
B C 0.96 A 0.87 E 0.41
C A 0.95 B 0.88 E 0.69
D C 0.99 B 0.84 …Run Code Online (Sandbox Code Playgroud) 我在 jupyter 笔记本上使用 seaborn,并且想要一个滑块来更新图表。我的代码如下:
from ipywidgets import interact, interactive, fixed, interact_manual
import numpy as np
import seaborn as sns
from IPython.display import clear_output
def f(var):
print(var)
clear_output(wait=True)
sns.distplot(list(np.random.normal(1,var,1000)))
interact(f, var=10);
Run Code Online (Sandbox Code Playgroud)
问题:每次移动滑块时,图表都会重复。我该如何更新图表?
python ×3
seaborn ×2
boxplot ×1
correlation ×1
ipywidgets ×1
matplotlib ×1
pandas ×1
python-2.7 ×1