将字符串转换为 pandas.core.series.Series 的浮点数

Converting a string to float for a pandas.core.series.Series

我正在尝试将以下 pandas.core.series.Series 转换为浮点数。 代码:

from yahoo_fin.options import get_calls
ticker = 'aapl'
ticker_calls = get_calls(ticker)
df = ticker_calls['Implied Volatility']
con = pd.Series(df).astype('float')

也试过:

df.astype('float')

输出:

could not convert string to float: '733.59%'

当刚刚打印 series/df 时,数据出现:

 1. 733.59%
 2. 657.03%
 3. 633.79%

但是我无法对此执行任何 statistics/math。最终目标是能够做到:

(df['Risk_free'] + df['IV'])

输出为:intfloat.

我要完成的示例:

['Risk_free']0.15 + ['IV']7.3359 = ['new col']7.35089

我现在得到的输出:

 4. 1.500%733.59%
 5. 1.500%657.03%

您可以去掉“%”符号..

from yahoo_fin.options import get_calls
ticker = 'aapl'
ticker_calls = get_calls(ticker)
df = ticker_calls['Implied Volatility']
con = df.str.rstrip('%').astype(float)

样本:

df = pd.Series(['12%', '12.5%', '35%', '50%', '88.880%'])
df.str.rstrip('%').astype(float)
0    12.00
1    12.50
2    35.00
3    50.00
4    88.88
dtype: float64