title: ValueError: The condensed distance matrix must contain only finite values. in python
body: <p>I wrote the following code for hierarchical clustering, but I get the following error, can you help me?</p>
  <pre><code># Importing the libraries
  
  import numpy as np
  import matplotlib.pyplot as plt
  import pandas as pd
  
  # Importing the Mall dataset with pandas
  
  dataset = 
  
  pd.read_csv(&quot;https://raw.githubusercontent.com/akbarhusnoo/Chronic-Kidney-Disease-Prediction/main/chronic_kidney_disease.csv&quot;, na_values=[&quot;?&quot;])
  
  
  catCols = dataset.select_dtypes(&quot;object&quot;).columns
  catCols = list(set(catCols))
  for i in catCols:
   dataset.replace({i: {'?': np.nan}}, regex=False,inplace=True)
  
  dataset.dropna(how='all')
  X = dataset.iloc[:, [3,4]].values
  
  # Using the dendrogram to find the optimal number of clusters
  
  import scipy.cluster.hierarchy as sch
  dendrogram = sch.dendrogram(sch.linkage(X, method='ward' ))
  plt.title('Dendrogram')
  plt.xlabel('C')
  plt.ylabel('Euclidean distances')
  plt.show()
  
  # Fitting the hierarchical clustering to the mall dataset
  
  from sklearn.cluster import AgglomerativeClustering
  hc = AgglomerativeClustering(n_clusters=5, affinity = 'euclidean', linkage = 'ward')
  Y_hc = hc.fit_predict(X)
  
  # Visualising the clusters
  </code></pre>
  <p>dataset:<a href="https://raw.githubusercontent.com/akbarhusnoo/Chronic-Kidney-Disease-Prediction/main/chronic_kidney_disease.csv" rel="nofollow noreferrer">https://raw.githubusercontent.com/akbarhusnoo/Chronic-Kidney-Disease-Prediction/main/chronic_kidney_disease.csv</a></p>
  <pre><code>**ValueError                                Traceback (most recent call last)
  &lt;ipython-input-30-2c6a60c0a6d0&gt; in &lt;module&gt;
       12 
       13 import scipy.cluster.hierarchy as sch
  ---&gt; 14 dendrogram = sch.dendrogram(sch.linkage(X, method='ward' ))
       15 plt.title('Dendrogram')
       16 plt.xlabel('C')
  
  ~\anaconda3\lib\site-packages\scipy\cluster\hierarchy.py in linkage(y, method, metric, optimal_ordering)
     1063 
     1064     if not np.all(np.isfinite(y)):
  -&gt; 1065         raise ValueError(&quot;The condensed distance matrix must contain only &quot;
     1066                          &quot;finite values.&quot;)
     1067 
  
  ValueError: The condensed distance matrix must contain only finite values.*
  </code></pre>
  <ul>
  <li></li>
  </ul>