0
當我向空DF添加或插入新列時,它不起作用。否則工作。向空數據框插入或添加新列不起作用
>>> dfTemp=pd.DataFrame()
>>> dfTemp
Empty DataFrame
Columns: []
Index: []
>>> dfTemp.insert(0, 'Company' , 'Apple')
>>> dfTemp.insert(1, 'Device' , 'ipad')
>>> dfTemp
Empty DataFrame
Columns: [Company, Device]
Index: []
>>> dfTemp = pd.DataFrame({"Year": [2017]})
>>> dfTemp.insert(0, 'Company' , 'Apple')
>>> dfTemp.insert(1, 'Device' , 'ipad')
>>> dfTemp
Company Device Year
0 Apple ipad 2017
>>> dfTemp = pd.DataFrame({"Year": [2017]})
>>> dfTemp['Company']='Apple'
>>> dfTemp['Device']='ipad'
>>> dfTemp
Year Company Device
0 2017 Apple ipad
>>> dfTemp=pd.DataFrame()
>>> dfTemp['Company']='Apple'
>>> dfTemp['Device']='ipad'
>>> dfTemp
Empty DataFrame
Columns: [Company, Device]
Index: []
什麼是解決方法,使其工作空DF?