Я пытаюсь преобразовать дюймы в футы из наборов данных о росте, но получаю ошибку.
Первые пять значений высоты столбца
0 73.847017
1 68.781904
2 74.110105
3 71.730978
Name: Height, dtype: float64
Код
def inch_to_feet(inch):
inch = float(inch[0])
return (inch / 12)
df['Height In Feet'] = df["Height"].apply(lambda x:inch_to_feet(x))
df
Ошибка
TypeError Traceback (most recent call last)
<ipython-input-88-a26935c05d6f> in <module>
3 return (inch / 12)
4
----> 5 df['Height In Feet'] = df["Height"].apply(lambda x:inch_to_feet(x))
6 df
~\Anaconda3\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds)
4040 else:
4041 values = self.astype(object).values
-> 4042 mapped = lib.map_infer(values, f, convert=convert_dtype)
4043
4044 if len(mapped) and isinstance(mapped[0], Series):
pandas\_libs\lib.pyx in pandas._libs.lib.map_infer()
<ipython-input-88-a26935c05d6f> in <lambda>(x)
3 return (inch / 12)
4
----> 5 df['Height In Feet'] = df["Height"].apply(lambda x:inch_to_feet(x))
6 df
<ipython-input-88-a26935c05d6f> in inch_to_feet(inch)
1 def inch_to_feet(inch):
----> 2 inch = float(inch[0])
3 return (inch / 12)
4
5 df['Height In Feet'] = df["Height"].apply(lambda x:inch_to_feet(x))
TypeError: 'float' object is not subscriptable
Это мой код и, пожалуйста, укажите некоторые другие Техника, а также, если это возможно. Заранее спасибо, ребята.