个人昵称:lxw-pro
个人主页:欢迎关注 我的主页
个人感悟: “失败乃成功之母”,这是不变的道理,在失败中总结,在失败中成长,才能成为IT界的一代宗师。
# 注意时区的设置
import time
# 获得当前时间时间戳
now = int(time.time())
# 转换为其他日期格式,如:"%Y-%m-%d %H:%M:%S"
timeArr = time.localtime(now)
other_StyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArr)
print(other_StyleTime)
import datetime
# 获得当前时间
now = datetime.datetime.now()
other_StyleTime = now.strftime("%Y-%m-%d %H:%M:%S")
print(other_StyleTime)
import datetime
def getYesterday():
today = datetime.date.today()
oneday = datetime.timedelta(days=1)
yesterday = today - oneday
return yesterday
print("昨天的日期:", getYesterday())
# 引入日历模块
import calendar
# 输入指定年月
yy = int(input("输入年份:"))
mm = int(input("输入月份:"))
# 显示指定年月
print(calendar.month(yy, mm))
import calendar
monthRange = calendar.monthrange(2022, 4)
print(monthRange)
import time
import datetime
# 先获得时间数组格式的日期
threeDayAgo = (datetime.datetime.now() - datetime.timedelta(days=3))
# 转换为时间戳
timeStamp = int(time.mktime(threeDayAgo.timetuple()))
# 转换为其他字符串格式
otherStyleTime = threeDayAgo.strftime("%Y-%m-%d %H:%M:%S")
print(otherStyleTime)
import time
import datetime
# 给定时间戳
timeStamp1 = 1643892140
dateArray = datetime.datetime.utcfromtimestamp(timeStamp1)
threeDayAgo = dateArray - datetime.timedelta(days=3)
print(threeDayAgo)
import time
timeStamp = 1825135462
timeArr = time.localtime(timeStamp)
other_StyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArr)
print(other_StyleTime)
或
import datetime
timeStamp = 2022020321
dateArr = datetime.datetime.utcfromtimestamp(timeStamp)
other_StyleTime = dateArray.strftime("%Y-%m-%d %H:%M:%S")
print(other_StyleTime)
————————————————————————————————————————————
print()只为换行用,方便看运行结果
# -*- coding = utf-8 -*-
# @Time : 2022/7/22 19:46
# @Author : lxw_pro
# @File : pandas-5 练习.py
# @Software : PyCharm
import pandas as pd
df = pd.read_excel('test-5.xlsx')
print("EXCEL数据如下:\n", df)
print()
print("df数据前5行为:\n", df.head())
print()
import re
def func(df):
zfg = df['popularity'].split('-')
smin = int(zfg[0].strip('f'))
smax = int(zfg[1].strip('f'))
df['popularity'] = int((smin+smax)/2)
return df
df = df.apply(func, axis=1)
print(df)
print()
fzj = df.groupby('project').mean()
print("分组后的平均分为:\n", fzj)
print()
df['date'] = df['test_time'].dt.date
df['time'] = df['test_time'].dt.time
print(df.head())
df.to_excel('text5.xlsx') # 也可将所运行的结果导入另一个新的EXCEL
21-22:
23-24:
25:
存入的新
EXCEL数据:
朋友间最美妙的发现,莫过于成长在不同的道路上,却并不因此滋生出隔阂!
点赞,你的认可是我创作的
动力
!
收藏,你的青睐是我努力的方向
!
评论,你的意见是我进步的财富
!
关注,你的喜欢是我长久的坚持
!
欢迎关注微信公众号【程序人生6】,一起探讨学习哦!!!