大家好,
小魯初學python數月
有些基礎還不是很熟
還請各位大大幫幫忙
目前是有一個function 但經過迴圈後的output
我試過將其存入一個pandas DataFrame
或是直接命名 result = function output
存入的檔案都只有1 kb...orz
還請各位高手幫忙
code如下:
lastName =[]
firstName =[]
mName =[]
import sys
def process(entries):
for line in entries:
arr = line.split()
if not arr:
continue
mName = arr.pop()
n = len(arr)
# if n == 4:
# lastName, mName = ' '.join(arr[:2]), ' '.join(arr[2:])
if n == 3:
# if arr[0] in ('M', 'Shk', 'BS'):
# first, middle = ' '.join(arr[:2]), arr[-1]
# else:
lastName, firstName,mName = arr[0], ' '.join(arr[1:]) , '
'.join(arr[1:]).split()[-1]
elif n == 2:
lastName, firstName = arr
else:
continue
print('First: %r' % firstName)
print('Middle: %r' % mName)
print('Last: %r' % lastName)
process(entries)
result = pd.DataFrame({'First Name': firstName,'Last Name':lastName, 'Middle
Name': mName})
with open("Faculty_Name_OK_1012.csv","w") as f:
print(result, file=f)