Excel 表格中的数据看起来像这样 Data 我首先按列读取数据,然后按行读取。Reading Data
一列相当于 15 分钟的时间段。在我的代码中,我将其捕获为 TimeID
。
现在我想根据excel格式转换时间ID。例如:
Time ID = 5
显示 6 am
TimeID = 1
显示 5 am
TimeID = 2
显示 5:15 am
等等....
import pandas as pd
import io
from google.colab import files
uploaded = files.upload()
df2 = pd.read_excel(io.BytesIO(uploaded['202009 Testing - September - Diamond Plod Day & Night MKY021.xlsm']),sheet_name='1 D',header=16,usecols="G:BF",nrows=21)
df3 = pd.read_excel(io.BytesIO(uploaded['202009 Testing - September - Diamond Plod Day & Night MKY021.xlsm']),sheet_name='1 D',header=7,usecols="C",nrows=4,skiprows=range(0,1))
df=pd.DataFrame()
Activities=[]
TimeID=[]
HoleID=[]
for column in range(0,52):
for row in range(0,21):
if df2.iloc[row,column] == 'X':
if row == 0:
Activities.append('Safety Meetings (Client)')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 1:
Activities.append('Safety Meetings (McKay)')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 2:
Activities.append('Travel Time')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 3:
Activities.append('Daily Pre-start Checks')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 4:
Activities.append('Rig Move/Setup')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 5:
Activities.append('Collaring the Hole ')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 6:
Activities.append('Drilling')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 7:
Activities.append('Surveys')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 8:
Activities.append('Pulling Rods')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 9:
Activities.append('Conditioning of Hole ')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 10:
Activities.append('Reaming')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 11:
Activities.append('Running Rods')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 12:
Activities.append('Mixing Additives')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 13:
Activities.append('Freeing stuck rods')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 14:
Activities.append('Bit changes ')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 15:
Activities.append('Casing operations – pull & run')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 16:
Activities.append('Standby (explain in Driller comments)')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 17:
Activities.append('Breakdown (Maint. comments)')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 18:
Activities.append('Planned Maint. (Maint. comments)')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 19:
Activities.append('Other (explain in Driller comments)')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
elif row == 20:
Activities.append('Equip Inspections (explain in Driller comments)')
TimeID.append(column+1)
HoleID.append(df3.iloc[0,0])
df['Activity'] = Activities
df['TimeID'] = TimeID
df['HoleID'] = HoleID
需要将TimeID
转成特定的excel格式。
有人可以帮我吗??
Google Colab:Code
Excel 文件:Attached