亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

利用python對(duì)excel中一列的時(shí)間數(shù)據(jù)更改格式操作

 更新時(shí)間:2020年07月14日 14:28:02   作者:楊遠(yuǎn)生  
這篇文章主要介紹了利用python對(duì)excel中一列的時(shí)間數(shù)據(jù)更改格式操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

問題場(chǎng)景:需要將下列的交期一列的數(shù)據(jù)格式更改成2019/05/10

存貨編碼 尺寸 數(shù)量 交期

0 K10Y0190000X B140 200 2019-05-10 00:00:00
1 K10Y0190000X B150 200 2019-05-10 00:00:00
2 K10Y0190000X B165 100 2019-05-10 00:00:00
3 K10Y0190000X B175 300 2019-05-10 00:00:00
4 K10Y0190000X B180 200 2019-05-10 00:00:00
5 K10B02400000 B130 400 2019-06-30 00:00:00
6 K10B02400000 B140 200 2019-06-30 00:00:00
7 K10B02400000 B170 800 2019-06-30 00:00:00
8 K10B02400000 B180 400 2019-06-30 00:00:00
9 K10B02400123 B120 100 2019-06-20 00:00:00

0.導(dǎo)入庫(kù)

import numpy as np
import pandas as pd
import time

1. 讀取數(shù)據(jù)

df=pd.DataFrame(pd.read_excel('C:\\Users\\yys\\Desktop\\請(qǐng)購(gòu)單.xlsx'))

2. 思路:將此列數(shù)據(jù)提取出來,存為列表,再更改格式,再放回表格中

#for循環(huán)選出需要數(shù)據(jù),存為列表
t_list=[]
for i in df['交期']:
	i=str(i)
	t1=time.strptime(i,"%Y-%m-%d %H:%M:%S")
	t2=time.strftime("%Y/%m/%d",t1)
	t_list.append(t2)

#將列表添加進(jìn)原本的表格數(shù)據(jù)中
df['交貨日期']=t_list

#刪除原本的日期
del df['交期']

3. 輸出至新的文件

df4.to_excel('E:\\yys\\請(qǐng)購(gòu)單_new.xlsx')

數(shù)據(jù)已經(jīng)更改成功;

存貨編碼 尺寸 數(shù)量 交貨日期

0 K10Y0190000X B140 200 2019/05/10
1 K10Y0190000X B150 200 2019/05/10
2 K10Y0190000X B165 100 2019/05/10
3 K10Y0190000X B175 300 2019/05/10
4 K10Y0190000X B180 200 2019/05/10
5 K10B02400000 B130 400 2019/06/30
6 K10B02400000 B140 200 2019/06/30
7 K10B02400000 B170 800 2019/06/30
8 K10B02400000 B180 400 2019/06/30
9 K10B02400123 B120 100 2019/06/20
10 K10B02400123 B140 100 2019/06/20

補(bǔ)充知識(shí):python 在excel文件中寫入date日期數(shù)據(jù),如何顯示為日期格式而不是數(shù)字

我就廢話不多說了,大家還是直接看代碼吧~

dateFormat = xlwt.XFStyle()

dateFormat.num_format_str = 'yyyy/mm/dd'

worksheet.write(0, 0, dt.date.today(),dateFormat)

以上這篇利用python對(duì)excel中一列的時(shí)間數(shù)據(jù)更改格式操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論