cd=pdd.read_excel(r"C:\Users\86172\Desktop\11.xlsx",sheet_name="Sheet2",header=[0,1])
时间: 2023-09-23 07:06:02 浏览: 51
Sorry, as an AI language model, I do not have access to your local files, so I cannot execute this code. However, this code seems to be reading an Excel file named "11.xlsx" from the desktop of the user "86172" and loading the data from the sheet named "Sheet2" into a pandas dataframe named "cd". The "header=[0,1]" argument suggests that the first two rows of the sheet contain column headers.
相关问题
设计一个Medicine(药品)类,包括药名(name)、价格(price)、生产日期(pd)、失效日期(exp)等属性,将价格、生产日期和失效日期设置为私有属性,不允许随意修改,类需要包括计算保质期的方法guarantee_period()和计算药品是否过期的方法is_expire()。用Python代码实现from datetime import datetime class Medicine(): def __init__(self,name,price,pd,exp): self.name=name self.__price=price self.__pd=pd self.__exp=exp def show(self): print("药品名称:",self.name) print("价格:",self.__price) def guarantee_period(self): date1=datetime.strptime(self.__pd,"%Y-%m-%d") date2=datetime.strptime(self.__exp,"%Y-%m-%d") minus=date2-date1 return f"保质期为{minus.days}天" def is_expire(self): today=datetime.now() pdd=datetime.strptime(self.__exp,"%Y-%m-%d") if today>pdd: return "药品已过期" else: return "药品未过期" if __name__=="__main__": s1=Medicine("冬凌草片",20,"2022-06-17","2024-06-17") s1.show() s1.guarantee_period() s1.is_expire()查看此答案的错误,给出修改方案
这个实现看起来已经很好了,但是在调用 `guarantee_period()` 和 `is_expire()` 方法时,没有打印出返回值。可以在调用方法时添加 `print()` 函数来打印返回值。
此外,如果想要用户能够修改药品价格、生产日期和失效日期,可以在类中添加相应的 setter 方法。修改后的代码如下:
```python
from datetime import datetime
class Medicine():
def __init__(self, name, price, pd, exp):
self.name = name
self.__price = price
self.__pd = pd
self.__exp = exp
def show(self):
print("药品名称:", self.name)
print("价格:", self.__price)
def guarantee_period(self):
date1 = datetime.strptime(self.__pd, "%Y-%m-%d")
date2 = datetime.strptime(self.__exp, "%Y-%m-%d")
minus = date2 - date1
return f"保质期为{minus.days}天"
def is_expire(self):
today = datetime.now()
pdd = datetime.strptime(self.__exp, "%Y-%m-%d")
if today > pdd:
return "药品已过期"
else:
return "药品未过期"
def set_price(self, price):
self.__price = price
def set_pd(self, pd):
self.__pd = pd
def set_exp(self, exp):
self.__exp = exp
if __name__ == "__main__":
s1 = Medicine("冬凌草片", 20, "2022-06-17", "2024-06-17")
s1.show()
print(s1.guarantee_period())
print(s1.is_expire())
s1.set_price(30)
s1.set_pd("2022-07-17")
s1.set_exp("2024-07-17")
s1.show()
print(s1.guarantee_period())
print(s1.is_expire())
```
这样,用户就可以通过类中的 setter 方法来修改药品的价格、生产日期和失效日期了。
func PostPddAfterList(a *decorator.ApiBase) error { logger.AccessLogger.Info("PostPddAfterList...") resp := pdd_epur.PddAfterListResponse{ResponseCommon: a.NewSuccessResponseCommon()} query := a.Ts.Table("pdd_after as a"). Select("a.id,b.pid,b.refunds_status,b.sum_amt,a.reason,a.after_type,a.after_status,b.order_time"). Joins("pdd_order_info as b on a.pid = b.pid"). Where("a.status = ?", model.Normal).Where("a.pid = ?", a.Token.LinkId) status := a.C.Param("after_status") switch status { case PDD_AFTER_STATUS_0: query = query.Where("a.after_type = ?", PDD_AFTER_STATUS_0) default: query = query.Where("a.after_type = ?", PDD_AFTER_STATUS_1) } utils.Error(query.Find(&resp.Data).Order("b.pid desc").Error) for i := range resp.Data { resp.Data[i].RefundsStatusName = GetPddRefundsStatusStatusMsg(resp.Data[i].RefundsStatus) resp.Data[i].AfterTypeName = GetPddAfterTypeMsg(resp.Data[i].AfterType) resp.Data[i].AfterStatusName = GetPddAFTERStatusStatusMsg(resp.Data[i].AfterStatus) } return a.ReturnSuccessCustomResponse(resp) }
这段代码是一个名为PostPddAfterList的函数,它接受一个名为a的decorator.ApiBase类型的指针作为参数,并返回一个错误。
在函数中,首先记录一条日志信息,然后创建一个名为resp的pdd_epur.PddAfterListResponse结构体对象,该结构体包含一个ResponseCommon字段,该字段由a.NewSuccessResponseCommon()方法创建。
接下来,使用查询构建器query查询pdd_after表和pdd_order_info表的字段,并根据条件进行过滤。条件包括a.status等于model.Normal和a.pid等于a.Token.LinkId。其中,a.C.Param("after_status")获取了一个名为after_status的参数,并根据不同的值设置不同的查询条件。
然后,使用query.Find()方法执行查询,并将结果存储在resp.Data中。同时,使用Order()方法对结果进行排序。
之后,使用一个for循环对resp.Data中的每个元素进行处理,设置一些字段的值。
最后,通过调用a.ReturnSuccessCustomResponse()方法,将resp作为自定义响应返回。
函数的作用是根据条件查询pdd_after表和pdd_order_info表的数据,并对结果进行处理后返回。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)