将带有时间戳的 excel 文件转换为 python 日期和时间
Convert excel file with timestamp to python date and time
如何将包含大量时间戳(即 1537892885364)的大型 .xlsx 文件转换为日期和时间(python,然后将其另存为新的 .xlsx 文件?
我是python的新手,我今天尝试了很多方法来实现这个,但我没有找到解决方案。
下面是我使用的代码,但它给了我“[Errno 13] 权限被拒绝”。我尝试了不同的方法,但也遇到了问题。
from __future__ import absolute_import, division, print_function
import os
import pandas as pd
def main(path, filename, absolute_path_organisation_structure):
absolute_filepath = os.path.join(path,filename)
#Relevant list formed with 4th, 5th and 6th columns
df = pd.read_excel(absolute_filepath, header=None, parse_cols=[4,5,6])
# Transform column 0 and 2 to datetime
df[0] = pd.to_datetime(df[0])
df[2] = pd.to_datetime(df[2])
print(df)
path = open(r'C:\Users\****\data')
MISfile = 'filename.xlsx'
main(path, MISfile,None)
希望对您有所帮助:
# requires the following packages:
# - pandas
# - xlrd
# - openpyxl
import pandas as pd
# reading in the excel file timestamps.xlsx
# this file contains a column 'epoch' with the unix epoch timestamps
df = pd.read_excel('timestamps.xlsx')
# translate epochs into human readable and write into newly created column
# note, your timestamps are in ms, hence the unit
df['timestamp'] = pd.to_datetime(df['epoch'],unit='ms')
# write to excel file 'new_timestamps.xlsx'
# index=False prevents pandas to add the indices as a new column
df.to_excel('new_timestamps.xlsx', index=False)
如何将包含大量时间戳(即 1537892885364)的大型 .xlsx 文件转换为日期和时间(python,然后将其另存为新的 .xlsx 文件?
我是python的新手,我今天尝试了很多方法来实现这个,但我没有找到解决方案。
下面是我使用的代码,但它给了我“[Errno 13] 权限被拒绝”。我尝试了不同的方法,但也遇到了问题。
from __future__ import absolute_import, division, print_function
import os
import pandas as pd
def main(path, filename, absolute_path_organisation_structure):
absolute_filepath = os.path.join(path,filename)
#Relevant list formed with 4th, 5th and 6th columns
df = pd.read_excel(absolute_filepath, header=None, parse_cols=[4,5,6])
# Transform column 0 and 2 to datetime
df[0] = pd.to_datetime(df[0])
df[2] = pd.to_datetime(df[2])
print(df)
path = open(r'C:\Users\****\data')
MISfile = 'filename.xlsx'
main(path, MISfile,None)
希望对您有所帮助:
# requires the following packages:
# - pandas
# - xlrd
# - openpyxl
import pandas as pd
# reading in the excel file timestamps.xlsx
# this file contains a column 'epoch' with the unix epoch timestamps
df = pd.read_excel('timestamps.xlsx')
# translate epochs into human readable and write into newly created column
# note, your timestamps are in ms, hence the unit
df['timestamp'] = pd.to_datetime(df['epoch'],unit='ms')
# write to excel file 'new_timestamps.xlsx'
# index=False prevents pandas to add the indices as a new column
df.to_excel('new_timestamps.xlsx', index=False)