我在python数据框中的astype有问题

问题描述 投票:0回答:1

我一直在尝试使用此代码解决问题:我正在尝试转换名为马力的字段的数据,我已经阅读了此站点中的许多文档和文章,但是我无法确定真正的问题是什么。

例如,我将“”更改为“,并仔细检查了空格和()[],还尝试了int的不同变体(int,” int“,int32,” int32“,int64” int64“))] >

请您让我知道错误的地方以及我必须做的代码更正

import pandas as pd
import numpy as np
from sklearn import linear_model
import sklearn.metrics as am
import matplotlib.pyplot as plt

filename = "https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/DA0101EN/auto.csv"

headers = ['symboling', 'normalized-losses', 'make', 'fuel-type', 'aspiration', 'num-of-doors', 
           'body-style','drive-wheels', 'engine-location', 'wheel-base', 'length', 'width', 
           'height', 'curb-weight', 'engine-type', 'num-of-cylinders', 'engine-size', 'fuel-system', 
           'bore', 'stroke', 'compression-ratio', 'horsepower', 'peak-rpm', 'city-mpg',
           'highway- mpg', 'price']

df = pd.read_csv(filename, names=headers)

df["horsepower"] = df["horsepower"].astype(int, copy=True)
    

我一直在尝试使用此代码解决问题:我正在尝试转换名为马力的字段的数据,我已经阅读了此站点中的许多文档和文章,但是我无法识别...

python python-3.x dataframe
1个回答
0
投票
ValueError: invalid literal for int() with base 10: '?'
© www.soinside.com 2019 - 2024. All rights reserved.