This video is a python program tutorial for reading row data (ASCII) with pandas library to a data frame, making some calculations on the selected data then exporting the results to excel along with generating graphs.
هذا الفيديو التعليمي باستخدام لغه البايثوتن لقراءه ملفات الرو داتا و اجراء عمليات حسابيه عليها ثم اصدار البيانات الى ملف اكسل شيت و رسوم بيانيه حسب طلب المستخدم
Docs for python libraries: https://docs.python.org/3/library/ind...
The code in the tutorial is below:
---------
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os
#================================ PARAMETERS =============================
n = 215 # Start point
m = 1000 # End point
N = 5 #space between two readings
#Read the folder path
package_dir = os.path.dirname(os.path.abspath(__file__))
add the name of the file to the folder path to get the absolute path
file= package_dir+'/RowData.log'
#Read the Row data file to the DATAFRAME and choosing the splitter option (tab '\t' or comma ',')
df_data = pd.read_csv(file,sep='\t')
df_data = pd.read_csv(file,sep=',')
print(df_data)
#========================= CONVERTING TIME AND DATE ======================
#Combine the [date] yyyy-mm-dd with the [clock] hh:mm:ss in a string and use the to_datetime method to convert it
df_data['comb_datetime'] = pd.to_datetime(df_data['Date']+' '+df_data['Clock'])
#============================ SUMMARY OF RESULTS ==========================
'''
Calculate the average value of the data in each required column
'''
avg_P = np.average(df_data.loc[n:m,'Pressure'])
avg_T = np.average(df_data.loc[n:m,'Temperature'])
avg_dP = np.average(df_data.loc[n:m,'dP'])
avg_oilRate = np.average(df_data.loc[n:m,'Std.OilFlowrate'])
avg_waterRate = np.average(df_data.loc[n:m,'WaterFlowrate'])
avg_std_gasRate= np.average(df_data.loc[n:m,'Std.GasFlowrate'])
avg_act_gasRate= np.average(df_data.loc[n:m,'Act.GasFlowrate'])
avg_GOR = np.average(df_data.loc[n:m,'GOR(std)'])
avg_WC = np.average(df_data.loc[n:m,'Std.Watercut'])
avg_oilSG = np.average(df_data.loc[n:m,'OilDensity'])
avg_waterSG = np.average(df_data.loc[n:m,'WaterDensity'])
avg_gasSG = np.average(df_data.loc[n:m,'GasDensity'])
avg_liquid = avg_oilRate + avg_waterRate
API = (141.5/(avg_oilSG/1000) - 131.5)
'''
Add all the averaged values into a dictionary called dict_summary
Then convert it to a DataFrame called summary
'''
dict_summary = { 'Delta time':'??????',
'Choke Size':'???????',
'WHP':avg_P,
'WHT':avg_T,
'Diff dP':avg_dP,
'Oil Rate':avg_oilRate,
'Water Rate':avg_waterRate,
'Liquid Rate':avg_liquid,
'Gas Rate':avg_std_gasRate,
'Actual Gas Rate':avg_act_gasRate,
'Total GOR':avg_GOR,
'Gas SG':avg_gasSG,
'Oil SG':avg_oilSG,
'Oil API':API,
'BSW':avg_WC,
}
summary = pd.DataFrame([dict_summary])
'''
Open an ExcelWriter (Panda function) and name it writer
define all the data that will be written in the excel sheet using the dataframe df_data with the .loc method
make sure to add the starting point and end point 'n' , 'm' & spaces between points 'N'
call function .to_excel and add the writer and the name of the sheet 'sheet1'
'''
writer = pd.ExcelWriter('output.xlsx')
df_data.loc[n:m:N,['Date', 'Clock', 'Pressure',
'Temperature', 'dP',
'Std.OilFlowrate', 'WaterFlowrate',
'Std.GasFlowrate', 'Act.GasFlowrate', 'GOR(std)',
'Act.OilFlowrate', 'Std.Watercut','OilDensity',
'WaterDensity', 'GasDensity'
]
].to_excel(writer,'sheet1')
'''
The same for the average sheet and call it 'sheet2'
Save to excel sheet with .save() method
'''
summary.to_excel(writer,'sheet2')
writer.save()
Make x as the x-axis value
x = df_data.loc[n:m,'comb_datetime']
Create the figure and add all the lines needed to be viewed in the graph
plt.figure()
plt.plot(x,df_data.loc[n:m,'Pressure'],'b-')
plt.plot(x,df_data.loc[n:m,'dP'],'g-')
plt.plot(x,df_data.loc[n:m,'Temperature'],'r-')
plt.margins(0.05)
plt.subplots_adjust(bottom=0.15)
plt.title( 'Pressure and Temperature')
plt.legend(['Pressure', 'dp','Temp'])
Create another figure
plt.figure()
plt.plot(x,df_data.loc[n:m,'Std.OilFlowrate'],'k-')
plt.plot(x,df_data.loc[n:m,'GOR(std)'],'g-')
plt.plot(x,df_data.loc[n:m,'WaterFlowrate'],'b-')
plt.legend(['Oil rate', 'GOR','Water rate'])
plt.title( 'Flow rate and GOR')
Create a third figure
plt.figure()
plt.plot(x,df_data.loc[n:m,'Std.GasFlowrate'],'y-')
plt.plot(x,df_data.loc[n:m,'Std.Watercut'],'b-')
plt.legend(['Gas rate', 'water rate'])
plt.title( 'Gas and water rate')
Show the graph with .show() method
plt.show()
Nesta página do site você pode assistir ao vídeo on-line Python tutorial for reading row data and exporting to Excel (Arabic) duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário mohammed albatati 22 Fevereiro 2021, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 456 vezes e gostou 60 espectadores. Boa visualização!