我写的函数似乎有一些问题。我想用它来阻止一个更大的文件。当我使用它时,我定义的变量是未定义的。你知道吗
在谷歌的colab平台上。你知道吗
def get_df2(file):
mydata2 = []
for chunk in pd.read_csv(file,chunksize=500000,header = None,sep='\t'):
mydata2.append(chunk)
user_data = pd.concat(mydata2,axis=0)
names2= ['user_id','age','gender','area','status','edu','ConAbility','device','work','CType','behhavior']
user_data.columns = names2
return user_data
我的函数是这样使用的:
user_data_path = 'myfile' #The file here is from my cloud, its detailed definition is too long, only abbreviations are given here.
get_df2(user_data_path)
user_data.head()
错误如下:
NameError Traceback (most recent call last)
<ipython-input-8-da7cac3b4241> in <module>()
1 get_df2(user_data_path)
----> 2 user_data.head()
NameError: name 'user_data' is not defined
有人能帮我吗?或者给我一个建议
您正在返回
user_data
,但没有将其绑定到函数范围之外的名称。您需要:相关问题 更多 >
编程相关推荐