为什么我得到AttributeError:“系列”对象没有属性“ to_datetime”和AttributeError:“ Series”对象没有属性“ concat”

时间:2019-08-06 17:40:27

标签: python-3.x pandas

此处设置数据https://drive.google.com/open?id=1r24rrKWcIpA1x34tPY8olJFMtjzl0IRn

我正在尝试将时间序列转换为DateTime类型,因此我需要将所有数字(例如(1256,430,7))设置为相同的大小,例如(1256,0430,0007)作为to_datetime ()工作。

所以我首先根据实体的长度分离实体,并添加所需的零数,将“系列”组合成一个单独的实体。

第一次错误

此错误是通过在Series中使用append()进行排序的。然后我尝试了to_datetime()

第二个错误

我不知道自己在做什么错

我更新了我的熊猫库。 问题仍然存在。 我在Google Colab上尝试过此操作,认为这可能是我的熊猫库中的问题。

a='0'+arr_time[arr_time.astype(str).str.len()==3].astype(int).astype(str)
b='0'+dep_time[dep_time.astype(str).str.len()==3].astype(int).astype(str)
c='00'+arr_time[arr_time.astype(str).str.len()==2].astype(int).astype(str)
d='00'+dep_time[dep_time.astype(str).str.len()==2].astype(int).astype(str) 
e='000'+arr_time[arr_time.astype(str).str.len()==1].astype(int).astype(str)
f='000'+dep_time[dep_time.astype(str).str.len()==1].astype(int).astype(str)
g=arr_time[arr_time.astype(str).str.len()==4].astype(int).astype(str)
h=dep_time[dep_time.astype(str).str.len()==4].astype(int).astype(str)

arr_time=pd.concat([a,c,e,g])
dep_time=pd.concat([b,d,f,h])

'''concat() is then replaced by append() ERROR detail is below

{AttributeError                            Traceback (most recent call 
last)
<ipython-input-20-61e7a2e98b70> in <module>()
----> 1 arr_time=pd.concat([aa,ba,ca,pa])
      2 dep_time=pd.concat([ad,bd,cd,pa])

/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in 
__getattr__(self, name)
   5065             if 
self._info_axis._can_hold_identifiers_and_holds_name(name):
   5066                 return self[name]
-> 5067             return object.__getattribute__(self, name)
   5068 
   5069     def __setattr__(self, name, value):

AttributeError: 'Series' object has no attribute 'concat'}'''

arr_time=a.append(c).append(e).append(g)
dep_time=b.append(d).append(f).append(h)
datetime=arr_time.to_datetime(format="%H%M")

'''second error  BOTH OF THEM LOOK ALIKE

{AttributeError                            Traceback (most recent call last)
<ipython-input-13-5a63dad5c284> in <module>
----> 1 datetime=arr_time.to_datetime(format="%H%M")

~\AppData\Local\Continuum\anaconda3\lib\site- packages\pandas\core\generic.py in __getattr__(self, name)
   5065             if 
self._info_axis._can_hold_identifiers_and_holds_name(name):
   5066                 return self[name]
-> 5067             return object.__getattribute__(self, name)
   5068 
   5069     def __setattr__(self, name, value):

AttributeError: 'Series' object has no attribute 'to_datetime'}'''

0 个答案:

没有答案