pandasライブラリを使用して簡単なexcelマージ操作を完了
8335 ワード
pandasライブラリを使用して簡単なexcelマージ操作を完了
number
name1
name2
name3
name4
name5
name6
name7
name8
name9
name10
0
1
ab
ab
ab
ab
ab
ab
ab
ab
ab
ab
1
2
bc
bc
bc
bc
bc
bc
bc
bc
bc
b
2
3
cd
cd
cd
cd
cd
cd
cd
cd
cd
cd
3
1
0
1
2
3
4
5
6
7
8
9
4
2
1
2
3
4
5
6
7
8
9
10
import os
import pandas as pd
'''
’ ‘
'''
# try:
# doc = os.listdir("./ ")
# f = open(' .txt', 'wb')
# for i in range(len(doc)):
# path = './ /'+doc[i]
# temp = open(path, 'rb')
# lines = temp.readlines()
# try:
# f.writelines(lines)
# print(' {} '.format(i+1))
# except:
# print(' {} , '.format(i+1))
# temp.close()
# print(' ')
# f.close()
# except:
# print(' , ‘ ’ , txt ')
'
’ ‘
'
s = '''
’ ‘
'''
print(s)
try:
dir2 = os.listdir(' /')
if len(dir2) <2:
print(' ')
else:
df = pd.read_excel(io=' /'+dir2[0],encoding = 'utf-8', header=1)
df.dropna(inplace = True)
for i in range(1,len(dir2)):
path2 = ' /'+dir2[i]
df2 = pd.read_excel(path2, endcoding = 'utf-8',skiprows=1, header= 0)
df2.dropna(inplace = True)
try:
df = pd.concat([df,df2], ignore_index = True, axis = 0)
print(' {} '.format(i+1))
except:
print(' {} '.format(i+1))
print(' ')
df.to_excel(' .xls')
except:
print(' , ‘ ’ , ')
’ ‘
2
3
df.head()
number
name1
name2
name3
name4
name5
name6
name7
name8
name9
name10
0
1
ab
ab
ab
ab
ab
ab
ab
ab
ab
ab
1
2
bc
bc
bc
bc
bc
bc
bc
bc
bc
b
2
3
cd
cd
cd
cd
cd
cd
cd
cd
cd
cd
3
1
0
1
2
3
4
5
6
7
8
9
4
2
1
2
3
4
5
6
7
8
9
10