我想实现我自己写的函数里的增加一行的功能用了apply,但是提示AttributeError错误
错误详情:AttributeError: 'TextFileReader' object has no attribute 'apply'
具体代码:
import pandas
import csv
import pandas as pd
tweets=pd.read_csv(open('C:\Users\zhang\我的毕业设计\data4_noted0313.csv',encoding='gb2312',errors='ignore'),iterator=True)
def num_space(str1):
num=0
for i in str1:
if (i==" "):
num+=1
else:
continue
return num
tweets['tNum_space'] = tweets.apply(lambda i:num_space(str(i['tTweet'])), axis=1)
tweets['tNum_space'] = tweets.apply(lambda i:num_space(str(i['tTweet'])), axis=1)