简体   繁体   English

在python函数中将列作为参数传递

[英]passing a column as parameter in python function

I have been trying to store unqiue values in a column from pandas data frame using the following code to further use in the function. 我一直在尝试使用下面的代码在pandas数据框中的一列中存储unqiue值,以进一步在函数中使用。 Code snippet: 程式码片段:

def mergeFields(data,field):

    oldlist = pd.unique(data[field])

data_rcvd_from_satish.tags = mergeFields("data_rcvd_from_satish","tags")

Error: 
TypeError: string indices must be integers, not list

I know the error which i have been getting is similar to many other question still I am not able to resolve the error. 我知道我得到的错误与许多其他问题相似,但我仍然无法解决该错误。 I would request not to consider this duplicate and please answer. 我要求不要考虑重复,请回答。

data is a string. data是一个字符串。 Please review the arguments passed to mergeFields . 请查看传递给mergeFields的参数。 you basically wrote: 您基本上写道:

"data_rcvd_from_satish"["tags"]

which is invalid. 这是无效的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM