Pandas:列对象不可调用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49217321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 05:18:30  来源:igfitidea点击:

Pandas: Column' object is not callable

pythonpandas

提问by Tom J Muthirenthi

I am trying to strip all the values after 'H' and store it to a column.

我试图去除 'H' 之后的所有值并将其存储到一列中。

df['col1'] = df['col1'].str.split('H').str[0]

df['col1'] = df['col1'].str.split('H').str[0]

But pyspark gives me error : Column' object is not callable

但是 pyspark 给了我错误:Column' 对象不可调用

采纳答案by jezrael

One possible solution is add expand=Truefor DataFrameand then select second column:

一个可能的解决方案是增加expand=TrueDataFrame,然后选择第二列:

df['col1'] = df['col1'].str.split('H', expand=True).iloc[:, 1]

Or:

或者:

df['col1'] = df['col1'].str.split('H', expand=True)[1]