Chinaunix
标题:
初学小白求助,每次循环产生的LIST怎么保存下来?
[打印本页]
作者:
rockyouhere
时间:
2019-05-21 21:20
标题:
初学小白求助,每次循环产生的LIST怎么保存下来?
导出只有只有list(n3)里面的内容,求助!
import pandas as pd
import os
pwd=os.getcwd()
workpath='C:\\Users\\CIB\\Desktop'
os.chdir(workpath)
condi_vn = [(40000,80000),(20000,40000),(7500,15000),(2500,5000)]
condi_worth = [(20000000,40000000),(10000000,20000000),(4000000,8000000),(1500000,3000000)]
condi_scale = ['大型','中型','小型','微型']
data=pd.read_excel('2019年4月核心客户档案库(3000户月报模版)结果数.XLSX',header=0,
sheet_name='201904',encoding='gbk')
final=pd.DataFrame()
for scale,vn,worth in zip(condi_scale,condi_vn,condi_worth):
n1 = data[(vn[0] < data['4月月均VN']) & (data['4月月均VN']<= vn[1])
& (worth[0] < data['4月财富业务年日均']) & (data['4月财富业务年日均']<= worth[1])]['单位名称']
n2 = data[(vn[0] < data['4月月均VN']) & (data['4月月均VN'] <= vn[1])
& (data['4月财富业务年日均'] <= worth[0])]['单位名称']
n3 = data[(data['4月月均VN'] <= vn[0])
& (worth[0] < data['4月财富业务年日均']) & (data['4月财富业务年日均'] <= worth[1])]['单位名称']
temp = list(n1)+list(n2)+list(n3)
cus = pd.DataFrame(temp)
final=cus
final.to_excel('output.xls')
复制代码
作者:
dahe_1984
时间:
2019-05-22 16:42
>>> import pandas as pd
>>> d = {'col1': [1, 2], 'col2': [3, 4]}
>>> df = pd.DataFrame(data=d)
>>> df
col1 col2
0 1 3
1 2 4
>>>
>>>
>>> d = {'col11': [1, 2], 'col12': [3, 4]}
>>> df = pd.DataFrame(data=d)
>>> df
col11 col12
0 1 3
1 2 4
-----------------------------------------
final.to_excel('output.xls') 应该写在循环里面
作者:
dahe_1984
时间:
2019-05-22 16:43
final.to_excel('output.xls') 这个也要追加模式,不知道这里支持不
作者:
dahe_1984
时间:
2019-05-22 17:13
>>> d = {'col1': [1, 2], 'col2': [3, 4]}
>>> df = pd.DataFrame(data=d, columns=['col1', 'col2'])
>>>
>>>
>>> df
col1 col2
0 1 3
1 2 4
>>>
>>>
>>>
>>> dd = {'col1': [11111, 2222], 'col2': [33333, 444444]}
>>> ddf = pd.DataFrame(data=dd, columns=['col1', 'col2'])
>>> df.append(ddf)
col1 col2
0 1 3
1 2 4
0 11111 33333
1 2222 444444
也可以这种方式。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2