pandas, Excel에 목록 쓰기

1885 단어 pandas
import numpy as np
import pandas as pd
from pandas import DataFrame
num_lis = [ 'BXD-201812-00053593','BXD-201812-00053550','BXD-201812-00053532',]
data_x = pd.read_excel(" .xlsx",usecols=[0,1,2,3,4])#pd.dataframe
//data_y =  pd.read_excel(" .xlsx",usecols=[5])

train_data = np.array(data_x)#np.ndarray()
train_x_list=train_data.tolist()#list

company_lis = []
fee_nums = []
name = []
notes = []
money = []
for li in train_x_list:
    if li[1] in num_lis:
        company_lis.append(li[0])
        fee_nums.append(li[1])
        name.append(li[2])
        notes.append(li[3])
        money.append(li[4])

dict_data = {
    'company':company_lis,
    'fee_nums':fee_nums,
    'name':name,
    'notes':notes,
    'money':money
}
data=DataFrame(dict_data)# 
DataFrame(data).to_excel('d.xlsx',sheet_name=' ')
=======================================================================================
 
from pandas.core.frame import DataFrame
a=[1,2,3,4]# a
b=[5,6,7,8]# b
c={"a" : a,
   "b" : b}# a,b 
data=DataFrame(c)# 
DataFrame(data).to_excel('b.xlsx',sheet_name=' ')

  from pandas.core.frame import DataFrame
a=[[1,2,3,4],[5,6,7,8]]# [1,2,3,4] [5,6,7,8]
data=DataFrame(a)#
print(data)
1
2
3
4
   0  1  2  3
0  1  2  3  4
1  5  6  7  8
1
2
3
data=data.T#
data.rename(columns={0:'a',1:'b'},inplace=True)# 0 1
print(data)
1
2
3
   a  b
0  1  5
1  2  6
2  3  7
3  4  8
--------------------- 
:Claroja 
:CSDN 
:https://blog.csdn.net/claroja/article/details/64439735 
: , !

좋은 웹페이지 즐겨찾기