Python如何整合excel 橫向、直向資料為一個表
各位高手好我是python新手~剛開始學習python
我有一個大量的資料表excel檔(內容大至如附件)
想請問各位~~該如何使用Python整合成一個等級表呢?
謝謝~~
2019-07-25 09:53
程序代码:Sub deal_data()
Dim r1, n As Integer
r1 = Range("a65530").End(xlUp).Row
r2 = 2
For i = 2 To r1
n = Len(Cells(i, 1)) - 1
m = Len(Cells(i - 1, 1)) - 1
If r2 < 3 And Right(Cells(i, 1), 1) = 1 Then
Cells(r2, 6) = Mid(Cells(i, 1), 1, n)
Cells(r2, 7) = Cells(i, 2)
End If
If Mid(Cells(i, 1), 1, n) = Mid(Cells(i - 1, 1), 1, m) And Right(Cells(i, 1), 1) = 2 Then '
Cells(r2, 8) = Cells(i, 2)
End If
If Mid(Cells(i, 1), 1, n) = Mid(Cells(i - 1, 1), 1, m) And Right(Cells(i, 1), 1) = 3 Then '
Cells(r2, 9) = Cells(i, 2)
r2 = r2 + 1
End If
If Mid(Cells(i, 1), 1, n) <> Mid(Cells(i - 1, 1), 1, m) And Right(Cells(i, 1), 1) = 1 Then
Cells(r2, 6) = Mid(Cells(i, 1), 1, n)
Cells(r2, 7) = Cells(i, 2)
End If
Next
End Sub

2019-08-05 16:28