将python中生成的输出导出到excel文件

将python中生成的输出导出到excel文件,python,pandas,data-science,Python,Pandas,Data Science,下面给出了部分数据,我想将数据从Jupyter笔记本的输出框导出到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 S

下面给出了部分数据,我想将数据从Jupyter笔记本的输出框导出到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\u 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中。

但是输出在输出窗口中,没有分配给任何变量。非常感谢您,它精确地解决了问题。这是一个完美且简单的方法,感谢您对问题的快速响应。谢谢,如果答案解决了您的问题,请进行投票并接受答案。