![](/img/trans.png)
[英]Vectorising pandas dataframe apply function for user defined function in python
[英]Apply user defined function to DataFrame fails, Python 3.6
我在数据框下方,想要将日期和文本与字段“ Indicator_NameB”分开,并且编写了函数“ String_Year_Pick_V2”
数据:
Indicator_NameB
2011-12 (RE)
2012-13 (BE)
2007-08
Approved Outlay
Total for 11th Plan
Data['Indicator_NameB'].map(str).apply(String_Year_Pick_V2)
KN.String_Year_Pick_V2
此函数将文本和日期与“ Indicator_NameB”的每个值分开,并以序列值形式返回,如(RE), 2011-12
出现以下错误:
AttributeError: 'builtin_function_or_method' object has no attribute 'get_indexer'
然后我更新到数据框:
DataT[['Indicator_NameB', 'Year']] = DataT['Indicator_NameB'].map(str).apply(String_Year_Pick_V2)
我猜测,
String_Year_Pick_V2('2007-08') gives '', '2007-08'
String_Year_Pick_V2('Approved Outlay') gives 'Approved Outlay', ''
可能高于导致错误的结果
String_Year_Pick_V2-函数具有多个return语句,我想返回序列值,并且某些代码将“ String”,“ Year”作为变量返回,这引起了错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.