文件读写
(1)with...open
with open('feature.txt','w') as f1:
for i in test['instance_id']:
f1.write(str(i)+'\n')
with open('feature.txt','r') as f2:
print(f2.read())
(2)pickle
import pickle
pickle.dump(df.columns.tolist(), open('feature','wb'))
feature_file = open('feature', 'rb')
feature_info= pickle.load(feature_file)
feature_info
(3)json
插入删除list/dict
>>> aa=[3,1,6]
>>> aa.pop()
6
>>> aa
[3, 1]
>>> bb=[33,11,66]
>>> bb.pop(0)
33
>>> bb
[11, 66]
>>> dic={'a':3,'b':1,'c':6}
>>> dic
{'a': 3, 'b': 1, 'c': 6}
>>> dic.pop('a')
3
>>> dic
{'b': 1, 'c': 6}
>>> ee=['A','B','C']
>>> ee.insert(1,10)
>>> ee
['A', 10, 'B', 'C']