我目前正试图操作数据以将文本值更改为Numeric,并在我的代码中收到以下错误。请帮忙。我使用的是juypter笔记本,一开始是进口熊猫作为pd并将数据集导入为dF
Null = dF.isnull() .any()
dF = dF.drop([["customerID", "gender", "SeniorCitizen", "Partner", "Dependents", "tenure", "PhoneService", "MultipleLines", "InternetService", "OnlineSecurity", "OnlineBackup", "DeviceProtection", "TechSupport", "StreamingTV", "StreamingMovies", "Contract", "PaperlessBilling", "PaymentMethod", "MonthlyCharges", "TotalCharges", "Churn"]], axis=1)
for column in range(len(list(dF.columns.values))):
for index, row in dF.iterrows():
if "No" in row[column] or "Female" in row[column]:
dF.iloc[index, column] = 0
elif "Yes" in row[column] or "Male" in row[column]:
dF.iloc[index, column] = 1
dF.to_excel('Clean.xlsx',index=False(
接收以下错误
File "<tokenize>", line 10
elif "Yes" in row[column] or "Male" in row[column]:
^
IndentationError: unindent does not match any outer indentation level
请参阅.drop((的文档。https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.drop.html你错过了几件事:
1. you're not actually dropping the rows (see inplace=True)
2. for more than one column it needs to be passed as list
3. you need to tell it the axis; defaults to index and you want columns
试着将其调整为您想要的(注意双括号(
df.drop([['col1', 'col2', ...]], axis=1, inplace=True)
你可以这样做:
df = df.drop([['col1', 'col2', ...]], axis=1)