【发布时间】:2021-05-04 17:47:13
【问题描述】:
我有一个数据框central
然后我想用sns.pairplot(central) 绘制列之间的成对关系。你能解释一下为什么这个过程永远运行吗?我在笔记本电脑和 Colab 上都试过了,但问题仍然存在。
import urllib3
%matplotlib inline
%config InlineBackend.figure_format = 'svg' # Change the image format to svg for better quality
import networkx as nx
import pandas as pd
import seaborn as sns
from scipy import stats
import matplotlib.pyplot as plt
## Import dataset
http = urllib3.PoolManager()
url = 'https://raw.githubusercontent.com/leanhdung1994/WebMining/main/airports.net'
f = http.request('GET', url)
open('airports.net', 'wb').write(f.data)
G = nx.read_pajek('airports.net', encoding = 'UTF-8')
G = nx.DiGraph(G)
## Compute measures of centrality
degree_central = nx.degree_centrality(G)
closeness_central = nx.closeness_centrality(G)
eigen_central = nx.eigenvector_centrality_numpy(G, max_iter = 200)
katz_central = nx.katz_centrality_numpy(G)
between_central = nx.betweenness_centrality(G)
pagerank = nx.pagerank_numpy(G)
[hub, authority] = nx.hits(G)
## Create a dataframe using with above calculated centralities
central = pd.DataFrame([degree_central, closeness_central, eigen_central, katz_central, between_central, hub, authority]).T
central.columns = ['degree', 'closeness', 'eigen', 'katz', 'between', 'hub', 'authority']
central
## Plot the pairwise relationships between centralities
sns.pairplot(central)
【问题讨论】:
-
问题是由列
eigen_central引起的,但我不知道这个问题的本质是什么。与所有其他列一样,该列包含 float64 值。它不包含 NaN 或 Inf 值。它是唯一包含负值的列,但这不应该是问题。当您向其中添加另一列时问题消失,但如果添加浮点值则不会。也许是一些棘手的 numpy 类型问题? -
有关此问题的更多信息:这不是此列的特定值,正如我一度怀疑的那样。您可以为任何
n绘制sns.pairplot(central.iloc[n:n+150, :]),但不能为sns.pairplot(central.iloc[n:n+200, :])绘制。不过,eigen_central的直方图看起来很奇怪,并且此列的孤立histplot也不起作用,所以看起来这是主要问题。我关注了这个问题并希望其他人可以阐明这种行为。
标签: python-3.x pandas matplotlib seaborn networkx