小编Jon*_*Kim的帖子

如何在d3.js中的节点上进行双击事件?

我想在节点上进行双击事件.所以我试过了

.on("dbclick",function(d){return "http://google.com");});
Run Code Online (Sandbox Code Playgroud)

.bind({"dbclick",function(d){alert("hello")} });
Run Code Online (Sandbox Code Playgroud)

但都失败了.谁能帮我?

完整代码如下.

var node = svg.selectAll(".node")
    .data(graph.nodes)
    .enter().append("g")
    .attr("class", "node")
    //.on("dbclick",function(d){return "http://google.com");});
    //.attr("xlink:href", function(d){return d.url;}
    .call(force.drag);
    //.bind({"dbclick",function(d){alert("hello")} });
Run Code Online (Sandbox Code Playgroud)

最后,我使用了以下方法.(dblclick也有效)

var node = svg.selectAll(".node") .data(graph.nodes) .enter().append("a") 
              .attr("class", "node") .attr("target", "_blank")
              .attr("xlink:href", function(d){return "google.com";;}) 
Run Code Online (Sandbox Code Playgroud)

svg d3.js

35
推荐指数
1
解决办法
3万
查看次数

Python Pandas到R dataframe

我将把Python pandas数据帧转换为R中的数据帧.我发现了这个问题的几个库

http://pandas.pydata.org/pandas-docs/stable/r_interface.html

这是rpy2

但我找不到保存或转移到R的方法.

首先我试过"to_csv"

df_R = com.convert_to_r_dataframe(df_total)
df_R.to_csv(direc+"/qap/detail_summary_R/"+"distance_"+str(gp_num)+".csv",sep = ",")
Run Code Online (Sandbox Code Playgroud)

但它给了我一个错误

"AttributeError: 'DataFrame' object has no attribute 'to_csv'  "
Run Code Online (Sandbox Code Playgroud)

所以我试着看看它的数据类型

<class 'rpy2.robjects.vectors.DataFrame'>
Run Code Online (Sandbox Code Playgroud)

我怎么能将这种类型的对象保存到csv文件或转移到R?

python r rpy2 pandas

14
推荐指数
3
解决办法
1万
查看次数

我们怎么能在anaconda上安装opencv?

我试图在Anaconda上安装OpenCV

pip install cv2
pip install opencv
conda install opencv
conda install -c https://conda.binstar.org/jjhelmus opencv
Run Code Online (Sandbox Code Playgroud)

(这里提到Anaconda找不到模块cv2)

但都失败了.有人知道如何安装吗?

python pip anaconda

11
推荐指数
2
解决办法
3万
查看次数

Python pandas,如何在没有列标签的情况下读取excel文件,然后插入列标签?

我有列表,我想将其作为列标签插入.但是当我使用read_excel的pandas时,他们总是将第0行视为列标签.我怎么能将该文件作为pandas数据帧读取,然后将列表作为列标签

  orig_index = pd.read_excel(basic_info, sheetname = 'KI12E00')

    0.619159  0.264191  0.438849  0.465287  0.445819  0.412582  0.397366  \
0   0.601379  0.303953  0.457524  0.432335  0.415333  0.382093  0.382361   
1   0.579914  0.343715  0.418294  0.401129  0.385508  0.355392  0.355123  
Run Code Online (Sandbox Code Playgroud)

这是我的列名列表

   print set_index
[20140109, 20140213, 20140313, 20140410, 20140508, 20140612]
Run Code Online (Sandbox Code Playgroud)

我想制作如下数据帧

    20140109  20140213  20140313  20140410  20140508  20140612
0   0.619159  0.264191  0.438849  0.465287  0.445819  0.412582  0.397366  \
1   0.601379  0.303953  0.457524  0.432335  0.415333  0.382093  0.382361   
2   0.579914  0.343715  0.418294  0.401129  0.385508  0.355392  0.355123
Run Code Online (Sandbox Code Playgroud)

excel pandas

10
推荐指数
1
解决办法
3万
查看次数

关于spyder和anaconda for python的一个非常基本的设置问题

我是Python的spyder IDE的初学者.

要使用spyder IDE,我使用python 2.7在anaconda控制台上命令"spyder"

之后,我尝试打印"hi"

但是我遇到了一条错误消息

"目前没有选择python shell来运行hu.py请选择或打开一个新的Python解释器并再试一次"

我怎么能解决这个问题?

我将文件保存在C:\ Anaconda\practice_jhk上

from __future__ import print_function
print ("hi")
Run Code Online (Sandbox Code Playgroud)

python spyder anaconda

6
推荐指数
1
解决办法
4万
查看次数

熊猫:我该如何迭代两个格式完全相同的数据框?

我的最终目标是制作包含一对对应数据帧位置的列表,如下所示

 [df_one_first_element, df_two_first_element, column_first, index_first]

 :[0.619159, 0.510162, 20140109,0.50], [0.264191,0.269053,20140213,0.50]...
Run Code Online (Sandbox Code Playgroud)

所以我试图迭代两个数据帧,但是现在卡住了。我如何迭代两个具有完全相同的格式但数据不同的数据框。

例如,我有两个数据框。df_one和df_two如下所示:

df_one = 

      20140109  20140213  20140313  20140410  20140508  20140612  20140710  \
0.50  0.619159  0.264191  0.438849  0.465287  0.445819  0.412582  0.397366   
0.55  0.601379  0.303953  0.457524  0.432335  0.415333  0.382093  0.382361  

df_two = 

      20140109  20140213  20140313  20140410  20140508  20140612  20140710  \
0.50  0.510162  0.269053  0.308494  0.300554  0.294360  0.286980  0.280494   
0.55  0.489953  0.258690  0.290044  0.283933  0.278180  0.271426  0.266580    
Run Code Online (Sandbox Code Playgroud)

我想通过遍历数据帧中的整个值来访问数据帧的相同位置。

首先我尝试了iterrows()

i = 0
for index, row in df_one.iterrows():
    j= 0
    for item in row:
        print …
Run Code Online (Sandbox Code Playgroud)

python pandas

6
推荐指数
3
解决办法
7307
查看次数

如何解释 Sklearn LDA 困惑度分数。为什么它总是随着主题数量的增加而增加?

我尝试使用 sklearn 的 LDA 模型找到最佳主题数。为此,我通过在https://gist.github.com/tmylk/b71bf7d3ec2f203bfce2上引用代码来计算困惑度。

但是当我增加话题数量时,困惑总是不合理地增加。我在实现上错了还是只是给出了正确的值?

from __future__ import print_function
from time import time

from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer
from sklearn.decomposition import NMF, LatentDirichletAllocation
n_samples = 0.7
n_features = 1000
n_top_words = 20
dataset = kickstarter['short_desc'].tolist()
data_samples = dataset[:int(len(dataset)*n_samples)]
test_samples = dataset[int(len(dataset)*n_samples):]
Run Code Online (Sandbox Code Playgroud)

对 LDA 使用 tf(原始术语计数)功能。

print("Extracting tf features for LDA...")
tf_vectorizer = CountVectorizer(max_df=0.95, min_df=2,
                                max_features=n_features,
                                stop_words='english')
t0 = time()
tf = tf_vectorizer.fit_transform(data_samples)
print("done in %0.3fs." % (time() - t0))
# Use tf (raw term count) features for …
Run Code Online (Sandbox Code Playgroud)

python topic-modeling scikit-learn perplexity

5
推荐指数
1
解决办法
8008
查看次数

标签 统计

python ×5

pandas ×3

anaconda ×2

d3.js ×1

excel ×1

perplexity ×1

pip ×1

r ×1

rpy2 ×1

scikit-learn ×1

spyder ×1

svg ×1

topic-modeling ×1