[英]to export the output generated in python to excel file
下面給出了部分數據,我想將 Jupyter Notebook 中輸出框中的數據導出到 excel 文件中。 數據非常龐大,就像 10k 行。
17:38:00 17:38:01 17:38:02 17:38:03 17:38:04 。 . . 以下是我的代碼:-
enter code here
import pandas as pd
import numpy as np
load_var=pd.read_csv(r'path')
# Select the dataframe
col_var=load_var['End Seconds']
# Converting the dataframe to array
a=col_var.values.tolist()
# define the function for time conversion
def convert(seconds):
seconds = seconds % (24 * 3600)
hour = seconds // 3600
seconds %= 3600
minutes = seconds // 60
seconds %= 60
return "%d:%02d:%02d" % (hour, minutes, seconds)
for n in a:
print(convert(n))
1)請建議在代碼中進行添加。
謝謝你。
使用df.to_excel()
導出到 excel 文件
df.to_excel(r'Path to store the exported excel file\File Name.xlsx', index = False)
您必須將您的功能應用到您要修改的系列,如下所示:
load_var = pd.read_csv(r'path')
load_var['End Seconds'] = load_var['End Seconds'].apply(convert)
現在您在內存中擁有轉換后的數據,可以使用 Fahmi 提到的df.to_excel()
將其保存到 Excel 中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.