Cannot convert Pandas Dataframe columns to float
I am using Pandas to read a CSV file containing several columns that must be converted to floats:

    df = pd.read_csv(r'dataset.csv',  low_memory=False,  sep = ',')
    df.head(2)

    Coal Flow 01    Air Flow 01 Outlet Temp 01  Inlet Temp 01   Bowl DP 01  Current 01  Vibration 01
    0   51.454407   101.432340  64.917089   234.2488932 2.470623    96.727352   1.874374
    1   51.625368   100.953089  64.726890   233.2340394 2.495698    96.309512   1.996391


Next I specify the columns that need to be converted to floats in a variable called features:

    features = ['Coal Flow 01', 'Air Flow 01', 'Outlet Temp 01', 'Inlet Temp 01',
           'Bowl DP 01', 'Current 01', 'Vibration 01']


Then I needed to convert the the value of the columns to float, but I got an error.

features = np.stack([df[col].values for col in features], 1)
features = torch.tensor(features, dtype=torch.float)
features[:5]


and the error that Pandas is showing me is:


  KeyError: "None of [Index([  51.45440668,   101.4323397,   64.91708906, '234.2488932',\n         2.470623484,   96.72735193,    1.87437372],\n      dtype='object')] are in the [columns]"


Why not just use astype:

df = pd.read_csv(r'dataset.csv',  low_memory=False,  sep = ',')
df[features] = df[features].apply(lambda x: x.apply(lambda x: x[0]).astype(float))

