Given below is some part of data, I want to export the data from output box in Jupyter Notebook to the excel file. The data is quite huge like 10k lines.
17:38:00 17:38:01 17:38:02 17:38:03 17:38:04 . . . Following is my code:-
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)Please suggest the addition to be made in the code.
Thank you.
使用df.to_excel()
导出到 excel 文件
df.to_excel(r'Path to store the exported excel file\File Name.xlsx', index = False)
You have to apply your function to the series that you want to modify like this:
load_var = pd.read_csv(r'path')
load_var['End Seconds'] = load_var['End Seconds'].apply(convert)
Now you have the converted data in memory which can be saved to Excel using df.to_excel()
as Fahmi mentioned.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.