0
는 다음과 같은 아주 간단한 예를 가지고 :팬더는 DatetimeIndex 형식 오류에 병합 : 유형의 객체를 'NoneType'더 LEN이 없습니다()
import pandas as pd
import numpy as np
import datetime
base = datetime.datetime(2016, 10, 1)
date_list = [base - datetime.timedelta(days=x) for x in range(0, 100)]
df1 = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'), index = date_list)
df2 = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'), index = date_list)
pd.merge(df1, df2, how = 'outer', left_on = True)
오류, 형식 오류 반환 타입의 객체를 'NoneType'더는 len (이 없습니다). 같은 DatetimeIndex 인 인덱스에서이 두 DataFrames를 병합하려면 병합이 어떻게 작동해야하는지 모르겠습니다.
내가 파이썬 2.7.12, 팬더 0.18.1 및 NumPy와를 실행하고 1.11.1
전체 역 추적은 "left_on
"할 수 있습니다 다음 documentation에서
TypeError Traceback (most recent call last)
<ipython-input-1-3174c0ff542d> in <module>()
9 df2 = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'), index = date_list)
10
---> 11 pd.merge(df1, df2, how = 'outer', left_on = True)
/Users/user/anaconda/lib/python2.7/site-packages/pandas/tools/merge.pyc in merge(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator)
36 right_on=right_on, left_index=left_index,
37 right_index=right_index, sort=sort, suffixes=suffixes,
---> 38 copy=copy, indicator=indicator)
39 return op.get_result()
40 if __debug__:
/Users/user/anaconda/lib/python2.7/site-packages/pandas/tools/merge.pyc in __init__(self, left, right, how, on, left_on, right_on, axis, left_index, right_index, sort, suffixes, copy, indicator)
208 (self.left_join_keys,
209 self.right_join_keys,
--> 210 self.join_names) = self._get_merge_keys()
211
212 def get_result(self):
/Users/user/anaconda/lib/python2.7/site-packages/pandas/tools/merge.pyc in _get_merge_keys(self)
405 left_keys, right_keys
406 """
--> 407 self._validate_specification()
408
409 left_keys = []
/Users/user/anaconda/lib/python2.7/site-packages/pandas/tools/merge.pyc in _validate_specification(self)
521 'of levels in the index of "left"')
522 self.left_on = [None] * n
--> 523 if len(self.right_on) != len(self.left_on):
524 raise ValueError("len(right_on) must equal len(left_on)")
525
TypeError: object of type 'NoneType' has no len()
될 것이다 중첩 인덱스 -'df1.join (df2, lsuffix = '_ l', rsuffix = '_ r') ' –
고마워요! 병합을위한 설명서를 완전히 읽었을 것입니다. –
'join '또한 1000 개의 루프, 3 : 468 μs의 루프 당 최대 병합'% timeit df1.join (df2, lsuffix = '_ l', rsuffix = '_ r') '병합보다 약간 빠르다. timeit pd.merge (df1, df2, left_index = True, right_index = True)'1000 개의 루프를 반환하며 루프 당 3 : 485 μs가 가장 좋습니다 –