我正试图从我们的中央银行获取一些数据,但无法解决这个问题。 (并且他们不提供支持......)
$client = new SoapClient("http://www.mnb.hu/arfolyamok.asmx?wsdl",array('trace' => 1));
$xml = new SimpleXMLElement($client->GetCurrentExchangeRates()->GetCurrentExchangeRatesResult);
echo $client->GetCurrentExchangeRates()->GetCurrentExchangeRatesResult;
echo (string)htmlentities($client->__getLastResponse());
我得到的结果是:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetCurrentExchangeRatesResponse xmlns="http://www.mnb.hu/webservices/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<GetCurrentExchangeRatesResult>
<MNBCurrentExchangeRates>
<Day date="2017-05-25">
<Rate unit="1" curr="AUD">204,7</Rate>
<Rate unit="1" curr="BGN">157,51</Rate>
<Rate unit="1" curr="BRL">83,66</Rate>
<Rate unit="1" curr="CAD">204,06</Rate>
<Rate unit="1" curr="CHF">282,21</Rate>
<Rate unit="1" curr="CNY">39,89</Rate>
<Rate unit="1" curr="CZK">11,65</Rate>
<Rate unit="1" curr="DKK">41,4</Rate>
<Rate unit="1" curr="EUR">308,06</Rate>
<Rate unit="1" curr="GBP">355,61</Rate>
<Rate unit="1" curr="HKD">35,17</Rate>
<Rate unit="1" curr="HRK">41,48</Rate>
<Rate unit="100" curr="IDR">2,06</Rate>
<Rate unit="1" curr="ILS">76,56</Rate>
<Rate unit="1" curr="INR">4,24</Rate>
<Rate unit="1" curr="ISK">2,73</Rate>
<Rate unit="100" curr="JPY">245,13</Rate>
<Rate unit="100" curr="KRW">24,49</Rate>
<Rate unit="1" curr="MXN">14,89</Rate>
<Rate unit="1" curr="MYR">64,07</Rate>
<Rate unit="1" curr="NOK">32,92</Rate>
<Rate unit="1" curr="NZD">192,59</Rate>
<Rate unit="1" curr="PHP">5,5</Rate>
<Rate unit="1" curr="PLN">73,67</Rate>
<Rate unit="1" curr="RON">67,7</Rate>
<Rate unit="1" curr="RSD">2,51</Rate>
<Rate unit="1" curr="RUB">4,88</Rate>
<Rate unit="1" curr="SEK">31,68</Rate>
<Rate unit="1" curr="SGD">197,91</Rate>
<Rate unit="1" curr="THB">8,01</Rate>
<Rate unit="1" curr="TRY">76,91</Rate>
<Rate unit="1" curr="UAH">10,43</Rate>
<Rate unit="1" curr="USD">274,03</Rate>
<Rate unit="1" curr="ZAR">21,23</Rate>
</Day>
</MNBCurrentExchangeRates>
</GetCurrentExchangeRatesResult>
</GetCurrentExchangeRatesResponse>
处理效果不是很好。所以我用过:
$res = (string)htmlentities($client->__getLastResponse());
$res = str_replace("<", "<", $res);
$res = str_replace(">", ">", $res);
echo $res;
由于某种原因,结果是:
<MNBCurrentExchangeRates>
<Day date="2017-05-25">
<Rate unit="1" curr="AUD">204,7</Rate>
<Rate unit="1" curr="BGN">157,51</Rate>
<Rate unit="1" curr="BRL">83,66</Rate>
<Rate unit="1" curr="CAD">204,06</Rate>
<Rate unit="1" curr="CHF">282,21</Rate>
<Rate unit="1" curr="CNY">39,89</Rate>
<Rate unit="1" curr="CZK">11,65</Rate>
<Rate unit="1" curr="DKK">41,4</Rate>
<Rate unit="1" curr="EUR">308,06</Rate>
<Rate unit="1" curr="GBP">355,61</Rate>
<Rate unit="1" curr="HKD">35,17</Rate>
<Rate unit="1" curr="HRK">41,48</Rate>
<Rate unit="100" curr="IDR">2,06</Rate>
<Rate unit="1" curr="ILS">76,56</Rate>
<Rate unit="1" curr="INR">4,24</Rate>
<Rate unit="1" curr="ISK">2,73</Rate>
<Rate unit="100" curr="JPY">245,13</Rate>
<Rate unit="100" curr="KRW">24,49</Rate>
<Rate unit="1" curr="MXN">14,89</Rate>
<Rate unit="1" curr="MYR">64,07</Rate>
<Rate unit="1" curr="NOK">32,92</Rate>
<Rate unit="1" curr="NZD">192,59</Rate>
<Rate unit="1" curr="PHP">5,5</Rate>
<Rate unit="1" curr="PLN">73,67</Rate>
<Rate unit="1" curr="RON">67,7</Rate>
<Rate unit="1" curr="RSD">2,51</Rate>
<Rate unit="1" curr="RUB">4,88</Rate>
<Rate unit="1" curr="SEK">31,68</Rate>
<Rate unit="1" curr="SGD">197,91</Rate>
<Rate unit="1" curr="THB">8,01</Rate>
<Rate unit="1" curr="TRY">76,91</Rate>
<Rate unit="1" curr="UAH">10,43</Rate>
<Rate unit="1" curr="USD">274,03</Rate>
<Rate unit="1" curr="ZAR">21,23</Rate>
</Day>
</MNBCurrentExchangeRates>
这不仅仅是奇怪的。我想清除这些lt和gt代码,但是丢失了&lt;&gt;输出中的零件。我想用simplexml获取数据,但无论我给它输出什么,它都会返回false。这是我想要使用的代码,但现在它只是给出了错误消息,因为$ xml的争用是“假”;
$xml = simplexml_load_string( (string)$res );
var_dump($xml);
foreach($xml->xpath('//Day') as $header) {
echo (string)$header->Rate;
}
(它实际上将结果XML放在一行中,我只是整理了一下。)
答案 0 :(得分:0)
In [267]: df = pd.DataFrame(index=range(5), columns=range(10))
...: S = pd.Series(np.random.randint(0,9,(18)))
...: df[1] = S
...:
In [268]: df
Out[268]:
0 1 2 3 4 5 6 7 8 9
0 NaN 3 NaN NaN NaN NaN NaN NaN NaN NaN
1 NaN 3 NaN NaN NaN NaN NaN NaN NaN NaN
2 NaN 1 NaN NaN NaN NaN NaN NaN NaN NaN
3 NaN 0 NaN NaN NaN NaN NaN NaN NaN NaN
4 NaN 6 NaN NaN NaN NaN NaN NaN NaN NaN
In [269]: df = df.astype('object')
...: df[:] = df.iloc[:,[1]]
...:
In [270]: df
Out[270]:
0 1 2 3 4 5 6 7 8 9
0 3 3 3 3 3 3 3 3 3 3
1 3 3 3 3 3 3 3 3 3 3
2 1 1 1 1 1 1 1 1 1 1
3 0 0 0 0 0 0 0 0 0 0
4 6 6 6 6 6 6 6 6 6 6