in learning data mining with python ch5 error
<p><strong>code:</strong></p>

<pre><code>import os
import pandas as pd
data_folder = os.path.join(os.path.expanduser("~"),"data","Ads")
data_filename = os.path.join(data_folder,"ad.data")
def convert_number(x):
    try:
        return float(x)
    except ValueError:
        return np.nan
from collections import defaultdict
converters = defaultdict(convert_number)
converters[1558] = lambda x:1 if x.strip() == "ad." else 0
ads = pd.read_csv(data_filename,header=None,converters=converters)
ads[:5]
x = ads.drop(1558,axis=1).values
y = ads[1558]
from sklearn.decomposition import PCA
pca = PCA(n_components=5)
xd = pca.fit_transform(x)
import numpy as np
np.set_printoptions(precision=3,suppress=True)
pca.explained_variance_ratio_
</code></pre>

<p><strong>error:</strong></p>

<pre><code>ValueError                                Traceback (most recent call last)
&lt;ipython-input-10-f726f2ff6f29&gt; in &lt;module&gt;()
      1 from sklearn.decomposition import PCA
      2 pca = PCA(n_components=5)
----&gt; 3 xd = pca.fit_transform(x)
      4 import numpy as np
      5 np.set_printoptions(precision=3,suppress=True)

/home/kongnian/anaconda3/lib/python3.5/site-packages/sklearn/decomposition/pca.py in fit_transform(self, X, y)
    239 
    240         """
--&gt; 241         U, S, V = self._fit(X)
    242         U = U[:, :self.n_components_]
    243 

/home/kongnian/anaconda3/lib/python3.5/site-packages/sklearn/decomposition/pca.py in _fit(self, X)
    266             requested.
    267         """
--&gt; 268         X = check_array(X)
    269         n_samples, n_features = X.shape
    270         X = as_float_array(X, copy=self.copy)

/home/kongnian/anaconda3/lib/python3.5/site-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
    371                                       force_all_finite)
    372     else:
--&gt; 373         array = np.array(array, dtype=dtype, order=order, copy=copy)
    374 
    375         if ensure_2d:

ValueError: could not convert string to float: '?'
</code></pre>

<p><strong>dataset:</strong>
<a href="http://archive.ics.uci.edu/ml/datasets/Internet+Advertisements" rel="nofollow">http://archive.ics.uci.edu/ml/datasets/Internet+Advertisements</a> download Advertisements dataset
<strong>os information:</strong>
Linux ubuntu 4.4.0-40-generic #60-Ubuntu SMP Fri Sep 23 16:45:45 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux</p>

<p>The data source you linked to contains <code>?</code> symbols - I presume these are missing values. I suggest to filter them during reading from csv stage, like so:</p>

<pre><code>ads = pd.read_csv(data_filename,header=None,converters=converters, na_values='?')
</code></pre>

<p>You may find more info on how to deal with missing values in <a href="http://pandas.pydata.org/pandas-docs/stable/" rel="nofollow">pandas docs</a></p>

python