pandas :FutureWarning:将类似列表的内容传递给.loc或[] [英] Pandas: FutureWarning: Passing list-likes to .loc or []
本文介绍了 pandas :FutureWarning:将类似列表的内容传递给.loc或[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行脚本时,Pandas提供以下信息:未来警告"
When I run my script, Pandas gives the following: 'Future warning'
FutureWarning:
Passing list-likes to .loc or [] with any missing label will raise
KeyError in the future, you can use .reindex() as an alternative.
我的脚本:
import io
data = io.StringIO('''A,B,M
AM,1,
AMC,2,
''')
df = pd.read_csv(data)
r=['CAR']
s=['CAR_M']
for i,j in zip(r,s):
df=df.append([{'A':i,'M':j}], ignore_index=True)
如果"ignore_index = False",将出现相同的警告.我不知道如何重新编制索引?
The same warning appear if "ignore_index=False". I don't know how to reindex?
推荐答案
似乎需要Series
构造函数才能正确追加新行:
It seems need Series
constructor for correct append new row:
for i,j in zip(r,s):
df=df.append(pd.Series({'A':i,'M':j}), ignore_index=True)
print (df)
A B M
0 AM 1.0 NaN
1 AMC 2.0 NaN
2 CAR NaN CAR_M
这篇关于 pandas :FutureWarning:将类似列表的内容传递给.loc或[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文