pandas 屏蔽 SettingWithCopyWarning A value is trying to be set on a copy of a slice from a DataFrame

http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html

pandas 屏蔽 SettingWithCopyWarning A value is trying to be set on a copy of a slice from a DataFrame_第1张图片

pandas 屏蔽 SettingWithCopyWarning A value is trying to be set on a copy of a slice from a DataFrame_第2张图片

添加如下一行代码:

# 不提示警告
pd.set_option('mode.chained_assignment', None)

 

# !/usr/bin/env python 
# -*- coding:utf-8 -*-
import pandas as pd


p = r"E:\test.txt"
pd.set_option('mode.chained_assignment', None)
df = pd.read_table(p)
need = df.iloc[2:]
need.columns = df.iloc[1]
need.index = need["Type"]
print("need.head() %s" % need.head())
print("need.loc[:, Version]=1 %s" % need.loc[:, "Version"])
need.loc["name1", "Version"] = "1.20.200"
print("need.loc[:, Version]=2 %s" % need.loc[:, "Version"])
print("df.iloc[:, 3] %s" % df.iloc[:, 3])

 

 

ps:

request模块也有屏蔽警告的,一起加,防止以后忘记了:

# 避免warning级别的警告(不显示)
requests.packages.urllib3.disable_warnings()

你可能感兴趣的:(pandas,爬虫)