我的计算机上有一个带有初始数据(值)的xlsx文件-创建了两张纸。我决定在sheet1和sheet2中计算一些值。之后,我尝试保存结果,但是当我从GoogleColab下载文件并获取具有初始值的起始文件时。
而且我不知道如何创建新的Sheet3并在其中进行计算:将Sheet1的一列复制到Sheet2的另一列,并将P_roz = P_nav + P-osvit
的结果复制到Sheet3的新列中。
如何下载图片2和图片4中的xlsx文件?
from google.colab import drive
drive.mount('/content/gdrive')
!pip install -q xlrd
import pandas as pd
import numpy as np
# Works with Sheet1
df_1 = pd.read_excel('my_path', name_sheet = 'Sheet1')
df_1['T_potyz'] = round((((1 / df_1['K_potyz']**2) - 1))**(1/2.0),3)
df_1['P_nav, кВт'] = df_1['P_ust, кВт']\
* df_1['K_poputy1']
df_1['Q_nav, кВАр'] = round(df_1['P_ust, кВт']\
* df_1['T_potyz'],3)
df_1['S_nav, кВА'] = round((df_1['P_nav, кВт']**2\
+ df_1['Q_nav, кВАр']**2)\
**(1/2.0),3)
df_1['P_nav, кВт'].sum(), df_1['Q_nav, кВАр'].sum(), df_1['S_nav, кВА'].sum()
sum_row1 = df_1[['P_nav, кВт', 'Q_nav, кВАр', 'S_nav, кВА']].sum()
sum_row1
# transpose the data and convert the Series to a DataFrame so that it is easier to concat onto our existing data.
#The T function allows us to switch the data from being row-based to column-based.
df_sum1 = pd.DataFrame(data = sum_row1).T
df_sum1
# to add the missing columns.
df_sum1 = df_sum1.reindex(columns = df_1.columns)
df_sum1
# add it to our existing one using append.
df_final_1 = df_1.append(df_sum1, ignore_index = True)
df_final_1.tail()
# Works with Sheet2
df_2 = pd.read_excel('my_path', sheet_name='Sheet2')
K_po = float(input("Коефіцієнт попиту загально освітлення: "))
df_2['P_ust'] = (round(df_2['k'] * df_2['P_put'] * 10**-3 *
df_2['A, м'] * df_2['B, м'],3))
df_2['P_osvit'] = round(K_po * df_2['P_ust'],3)
df_2['T_potyz2'] = round((((1 / df_2['K_poputy2']**2) - 1))**(1/2.0),3)
df_2['Q_osvit'] = round(df_2['P_osvit'] * df_2['T_potyz2'],3)
df_2['S_osvit'] = round((df_2['P_osvit']**2\
+ df_2['Q_osvit']**2)\
**(1/2.0),3)
df_2['P_osvit'].sum(), df_2['Q_osvit'].sum(), df_2['S_osvit'].sum()
sum_row2 = df_2[['P_osvit', 'Q_osvit', 'S_osvit']].sum()
sum_row2
df_sum2 = pd.DataFrame(data = sum_row2).T
df_sum2
df_sum2 = df_sum2.reindex(columns = df_2.columns)
df_sum2
df_final2 = df_2.append(df_sum2, ignore_index = True)
df_final2.tail()
# Here I want create a new Sheet3 and make some calculation
P_roz = df_1['P_nav, кВт'] + df_2['P_osvit']
Q_roz = df_1['Q_nav, кВАр'] + df_2['Q_osvit']
S_roz = (P_roz**2 + Q_roz**2)**(1 / 2.0)
frame_data3 = {'P_roz' : [P_roz], 'Q_roz' : [Q_roz], 'S_roz' : [S_roz]}
df_4 = pd.DataFrame(frame_data3)
df_4