0
我想對此Dataframe進行分類(名爲:loandata),並將每個子數據框導入許多csv文件。第一步,我嘗試轉換的結果之一,但不幸失敗了,得到這個錯誤:TypeError:不能將'模塊'對象隱式轉換爲str
import pandas as pd
import csv
import os
#readfile
loandata=pd.DataFrame(pd.read_table('/Users/lixuefei/Desktop/Sample Dataset/test.txt',header = None,index_col=2))
#classify
volume_type=list(set(loandata[3]))
system_type=list(set(loandata[4]))
area_name=list(set(loandata[5]))
df=pd.DataFrame(loandata[(loandata[3]==volume_type[0])& (loandata[4]==system_type[0])&(loandata[5]==area_name[0])])
#set the file path
path='/Users/lixuefei/Desktop/Sample Dataset'
filename=volume_type[0]+system_type[0]+area_name[0]
filetype=csv
if not df.empty:
df.to_csv(os.path.join(path,filename+filetype),header=None)
else:
print("Empty")
,這是錯誤:
/Users/lixuefei/anaconda/bin/python3.5/Users/lixuefei/PycharmProjects/project/project.11.09.py
Traceback (most recent call last):
File "/Users/lixuefei/PycharmProjects/project/project.11.09.py", line 25, in <module>
df.to_csv(os.path.join(path,filename+filetype),header=None)
TypeError: Can't convert 'module' object to str implicitly
您將模塊分配給變量'filetype = csv' - 您忘記了''''''filetype =「csv」'或者事件'filetype =「。csv」' – furas