使用.pandas上的.str时出现设置副本警告警告

2024-04-25 14:57:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图将.str[]应用于中的数据,以便从字符串中获取特定字符,但出现了“SettingWithCopyWarning”错误。你知道吗

import pandas as pd

df_temp = pd.read_csv("C:\\Users\\Bill-PC\\PycharmProjects\\QC Data\\Testing\\10 PP 1 2 again.txt", sep="\t", low_memory=False)

df_temp = df_initial.loc[df_initial["Sample Type"] == "Quality Control"]

df_temp["QC Level"] = df_temp["Sample Name"].str[-1:]

我得到以下错误

<input>:3: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

Tags: 数据sample字符串dfvalue错误temploc
1条回答
网友
1楼 · 发布于 2024-04-25 14:57:27

顺便说一下,这不是一个错误,它只是一个警告,但尝试这个我希望警告不会显示

df.loc[:,"City"] = df['City'].str[-1:]

相关问题 更多 >