【发布时间】:2020-07-19 15:36:01
【问题描述】:
鉴于以下 pandas 数据框,我如何创建一个对象数组,其中包含 2020 年至 2015 年之间的行中的所有值?假设数据框中包含 2020 年到 2010 年的数据。
Year Yield Total Amount ExDate PayDate \
0 2020 3.09% SGD 0.66 SGD0.33 2020-05-12 2020-05-26
1 2020 3.09% SGD 0.66 SGD0.33 2020-05-12 2020-05-26
2 2019 7.02% SGD 1.5 SGD0.3 2019-11-18 2019-11-29
3 2019 7.02% SGD 1.5 SGD0.3 2019-08-05 2019-08-20
4 2019 7.02% SGD 1.5 SGD0.3 2019-05-17 2019-05-31
5 2019 7.02% SGD 1.5 SGD0.6 2019-05-02 2019-05-17
6 2018 7.95% SGD 1.7 SGD0.6 2018-08-08 2018-08-21
7 2018 7.95% SGD 1.7 SGD0.6 2018-05-03 2018-05-15
8 2018 7.95% SGD 1.7 SGD0.5 2018-05-03 2018-05-15
9 2017 2.95% SGD 0.63 SGD0.33 2017-08-11 2017-09-27
对象:
class Object:
def__init(self, year, yield_data, amount, total, ex_date, pay_date):
self.year = year
self. yield_data = yield_data
self.total = total
self.ex_date = ex_date
self.pay_date = pay_date
self.amount = amount
【问题讨论】:
-
你能解释一下
year must only appear once in the array of objects.吗,因为在2019这一年有不同的条目有不同的ExdDate和PayDate? -
是的,刚刚意识到这没有意义。编辑了问题。希望它现在更有意义。
-
@Sushanth 不,我再次编辑了它
标签: python python-3.x pandas python-3.7