亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 Python 類對象轉換為 DataFrame

將 Python 類對象轉換為 DataFrame

精慕HU 2021-09-28 13:53:52
如何將具有實例化其他類的字段的 Python 類對象轉換為 DataFrame?我嘗試了下面的代碼,但它不起作用。當我取出時self.address = Address(),我可以讓它工作self.agency_contact_info = ContactInfo()class Address:    def __init__(self):        self.address_one = "address 1"        self.address_two = "P.O. BOX 1"                  class ContactInfo:    def __init__(self):        self.person_name = "Me"        self.phone_number = "999-999-9999"    class AgencyRecord:    def __init__(self):        self.agency_code = "00"        self.agency_id = "000"        self.agency_name = "Some Agency"        self.address = Address()        self.agency_contact_info = ContactInfo()            def create_data():    data = {}    for i in range(0, 3):        alc = AgencyRecord()                            data[i] = alc       column_list = [        'agency_code', 'agency_id', 'agency_name',         'address_one', 'address_two', 'person_name', 'phone_number'    ]    spark.createDataFrame(        list(data.values()),        column_list    ).createOrReplaceTempView("MyTempTable")
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 647 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號