我有两个数据帧,一个有很多行,另一个有几行,我需要根据一些条件(在字符串中)合并这两个数据帧。我在Pandas中使用嵌套循环,如下所示:
density = []
for row in df.itertuples():
for row1 in df2.itertuples():
if(row['a'].find(row1['b']))>0:
density.append(row1['c'])
但我收到错误信息:
TypeError: tuple indices must be integers, not str
怎么了?你知道吗
Tags:
方法数据帧.itertuples返回namedtuple,要访问namedtuple中的值,必须使用点表示法。你知道吗
然而,这不会产生两个数据帧的合并。你知道吗
考虑
df
和df2
你可以用
get_value
和set_value
产生不错的速度。我将这些值存储在一个数据帧中也可以使用复合
numpy
str
函数相关问题 更多 >
编程相关推荐