TypeError : 'str'및 'float'개체를 연결할 수 없습니다. : Pandas

생강 빵

팬더를 사용하여 데이터 과학 문제를 해결하려고합니다. 내 데이터 세트에는 "country", "conversion", "test", "userid"등의 열이 포함되어 있습니다. country 열에는 약 10 개국이 있습니다. "테스트"열에는 두 가지 유형의 테스트, 즉 0에 대한 통제와 1에 대한 실험을 나타내는 값 0과 1이 있습니다. "전환"에는 사람이 전환했는지 여부를 나타내는 값 0과 1도 있습니다.

국가별로 그룹화하고 모든 그룹에 대해 p- 값과 test == 0 및 test == 1의 평균을 계산하고 싶습니다. 다음 함수를 사용하려고하는데 "TypeError : cannot concatenate 'str'and 'float'objects"라는 오류가 발생합니다. 누군가 이것에 대해 밝힐 수 있습니까?

def f(x):
        control = x.loc[(x.test==0)]
        test = x.loc[(x.test==1)]
        p_value = stats.ttest_ind(control,test)[0]
        control_mean = control['conversion'].mean()
        test_mean = test['conversion'].mean()
        return pd.Series({'p_value': p_value, 'conversion_test': test_mean, 'conversion_control': control_mean})     

bycountry = data1.groupby('country').apply(f) 
bycountry = bycountry.reset_index(level='None')
bycountry

전체 오류 메시지 :

TypeError                                 Traceback (most recent call last)
<ipython-input-495-bd6227878520> in <module>()
      7     return pd.Series({'p_value': p_value, 'conversion_test': test_mean, 'conversion_control': control_mean})
      8 
----> 9 bycountry = data1.groupby("country").apply(f)
     10 bycountry = bycountry.reset_index(level='None')
     11 bycountry

C:\Users\SnehaPriya\Anaconda2\lib\site-packages\pandas\core\groupby.pyc in apply(self, func, *args, **kwargs)
    649         # ignore SettingWithCopy here in case the user mutates
    650         with option_context('mode.chained_assignment', None):
--> 651             return self._python_apply_general(f)
    652 
    653     def _python_apply_general(self, f):

C:\Users\SnehaPriya\Anaconda2\lib\site-packages\pandas\core\groupby.pyc in _python_apply_general(self, f)
    653     def _python_apply_general(self, f):
    654         keys, values, mutated = self.grouper.apply(f, self._selected_obj,
--> 655                                                    self.axis)
    656 
    657         return self._wrap_applied_output(

C:\Users\SnehaPriya\Anaconda2\lib\site-packages\pandas\core\groupby.pyc in apply(self, f, data, axis)
   1525             # group might be modified
   1526             group_axes = _get_axes(group)
-> 1527             res = f(group)
   1528             if not _is_indexed_like(res, group_axes):
   1529                 mutated = True

C:\Users\SnehaPriya\Anaconda2\lib\site-packages\pandas\core\groupby.pyc in f(g)
    645         @wraps(func)
    646         def f(g):
--> 647             return func(g, *args, **kwargs)
    648 
    649         # ignore SettingWithCopy here in case the user mutates

<ipython-input-495-bd6227878520> in f(x)
      2     control = x.loc[(x.test==0)]
      3     test = x.loc[(x.test==1)]
----> 4     p_value = stats.ttest_ind(control,test)[0]
      5     control_mean = control['conversion'].mean()
      6     test_mean = test['conversion'].mean()

C:\Users\SnehaPriya\Anaconda2\lib\site-packages\scipy\stats\stats.pyc in ttest_ind(a, b, axis, equal_var, nan_policy)
   3865         return Ttest_indResult(np.nan, np.nan)
   3866 
-> 3867     v1 = np.var(a, axis, ddof=1)
   3868     v2 = np.var(b, axis, ddof=1)
   3869     n1 = a.shape[axis]

C:\Users\SnehaPriya\Anaconda2\lib\site-packages\numpy\core\fromnumeric.pyc in var(a, axis, dtype, out, ddof, keepdims)
   3098 
   3099     return _methods._var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
-> 3100                          keepdims=keepdims)

C:\Users\SnehaPriya\Anaconda2\lib\site-packages\numpy\core\_methods.pyc in _var(a, axis, dtype, out, ddof, keepdims)
     89     # Note that if dtype is not of inexact type then arraymean will
     90     # not be either.
---> 91     arrmean = umr_sum(arr, axis, dtype, keepdims=True)
     92     if isinstance(arrmean, mu.ndarray):
     93         arrmean = um.true_divide(

TypeError: cannot concatenate 'str' and 'float' objects

df.dtypes의 출력 :

user_id                      int64
date                datetime64[ns]
source                      object
device                      object
browser_language            object
ads_channel                 object
browser                     object
conversion                   int64
test                         int64
sex                         object
age                        float64
country                     object
dtype: object
생강 빵
def f(x):
    control = x.loc[(x.test==0)]
    control = control['conversion']
    test = x.loc[(x.test==1)]
    test = test['conversion']
    p_value = stats.ttest_ind(control,test)[0]
    control_mean = control.mean()
    test_mean = test.mean()
    return pd.Series({'p_value': p_value, 'conversion_test': test_mean, 'conversion_control': control_mean})     

이것은 트릭을했다 !! juanpa.arrivillaga @ 다시 감사합니다 !!

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

TypeError : Flask의 'str'및 'float'개체를 MySQL과 연결할 수 없습니다.

분류에서Dev

TypeError : 'str'및 'function'객체를 연결할 수 없습니다.

분류에서Dev

Tkinter Label, TypeError : 'str'및 'instance'개체를 연결할 수 없습니다.

분류에서Dev

Python Selenium TypeError : 'str'및 'WebElement'개체를 연결할 수 없습니다.

분류에서Dev

Python TypeError : 인쇄를 시도 할 때 'str'및 'int'개체를 연결할 수 없습니다.

분류에서Dev

TypeError : '<class'str '>'유형의 개체를 연결할 수 없습니다. Series 및 DataFrame obj 만 유효합니다.

분류에서Dev

re.search () TypeError : 'str'및 'NoneType'객체를 연결할 수 없습니다.

분류에서Dev

TypeError : scrapy.Request ()에 맞춤 URL을 배치 할 때 'str'및 'NoneType'개체를 연결할 수 없습니다.

분류에서Dev

TypeError : 'float'개체를 str 암시 적으로 변환 할 수 없거나 TypeError :-: 'str'및 'float'에 대해 지원되지 않는 피연산자 유형

분류에서Dev

형식 오류는 'str'및 'ErrorList'개체를 연결할 수 없습니다.

분류에서Dev

Python 오류 : 'str'및 'builtin_function_or_method'개체를 연결할 수 없습니다.

분류에서Dev

TypeError : str에 바이트를 연결할 수 없습니다.

분류에서Dev

Python : TypeError : 'str'과 'int'를 연결할 수 없습니다.

분류에서Dev

Python TypeError : 메시지의 이메일 본문 부분에서 'str'및 'list'개체를 연결할 수 없습니다.

분류에서Dev

TypeError : DataFrame에서 str ( "float"아님) 만 str에 연결할 수 있습니다.

분류에서Dev

TypeError : 'str'과 'NoneType'객체를 연결할 수 없습니다 .python BS4

분류에서Dev

django-selenium TypeError : 'str'개체를 호출 할 수 없습니다.

분류에서Dev

xml에 디렉터리 목록- 'str'및 'NoneType'개체를 연결할 수 없습니다. 처리 방법?

분류에서Dev

TypeError : str ( "list"아님) 만 str에 연결할 수 있습니다.-Pandas

분류에서Dev

discord.py TypeError에 문제가 있습니다 : str ( "float"아님) 만 str에 연결할 수 있습니다.

분류에서Dev

TypeError : print를 호출 할 때 'str'개체를 호출 할 수 없습니다.

분류에서Dev

" 'float'개체를 암시 적으로 str로 변환 할 수 없습니다."

분류에서Dev

python "TypeError : 'numpy.float64'개체를 정수로 해석 할 수 없습니다."

분류에서Dev

TypeError : 'list'개체를 암시 적으로 str로 변환 할 수 없습니다.

분류에서Dev

TypeError : 파일을 읽을 때 'str'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'str'개체는 MySQL에서 호출 할 수 없습니다.

분류에서Dev

TypeError : 'numpy.float64'개체를 호출 할 수 없습니까?

분류에서Dev

TypeError : 계산을 인쇄 한 후 'float'개체를 호출 할 수 없습니다.

분류에서Dev

계산기 오류 : TypeError : 'float'개체를 호출 할 수 없습니다.

Related 관련 기사

  1. 1

    TypeError : Flask의 'str'및 'float'개체를 MySQL과 연결할 수 없습니다.

  2. 2

    TypeError : 'str'및 'function'객체를 연결할 수 없습니다.

  3. 3

    Tkinter Label, TypeError : 'str'및 'instance'개체를 연결할 수 없습니다.

  4. 4

    Python Selenium TypeError : 'str'및 'WebElement'개체를 연결할 수 없습니다.

  5. 5

    Python TypeError : 인쇄를 시도 할 때 'str'및 'int'개체를 연결할 수 없습니다.

  6. 6

    TypeError : '<class'str '>'유형의 개체를 연결할 수 없습니다. Series 및 DataFrame obj 만 유효합니다.

  7. 7

    re.search () TypeError : 'str'및 'NoneType'객체를 연결할 수 없습니다.

  8. 8

    TypeError : scrapy.Request ()에 맞춤 URL을 배치 할 때 'str'및 'NoneType'개체를 연결할 수 없습니다.

  9. 9

    TypeError : 'float'개체를 str 암시 적으로 변환 할 수 없거나 TypeError :-: 'str'및 'float'에 대해 지원되지 않는 피연산자 유형

  10. 10

    형식 오류는 'str'및 'ErrorList'개체를 연결할 수 없습니다.

  11. 11

    Python 오류 : 'str'및 'builtin_function_or_method'개체를 연결할 수 없습니다.

  12. 12

    TypeError : str에 바이트를 연결할 수 없습니다.

  13. 13

    Python : TypeError : 'str'과 'int'를 연결할 수 없습니다.

  14. 14

    Python TypeError : 메시지의 이메일 본문 부분에서 'str'및 'list'개체를 연결할 수 없습니다.

  15. 15

    TypeError : DataFrame에서 str ( "float"아님) 만 str에 연결할 수 있습니다.

  16. 16

    TypeError : 'str'과 'NoneType'객체를 연결할 수 없습니다 .python BS4

  17. 17

    django-selenium TypeError : 'str'개체를 호출 할 수 없습니다.

  18. 18

    xml에 디렉터리 목록- 'str'및 'NoneType'개체를 연결할 수 없습니다. 처리 방법?

  19. 19

    TypeError : str ( "list"아님) 만 str에 연결할 수 있습니다.-Pandas

  20. 20

    discord.py TypeError에 문제가 있습니다 : str ( "float"아님) 만 str에 연결할 수 있습니다.

  21. 21

    TypeError : print를 호출 할 때 'str'개체를 호출 할 수 없습니다.

  22. 22

    " 'float'개체를 암시 적으로 str로 변환 할 수 없습니다."

  23. 23

    python "TypeError : 'numpy.float64'개체를 정수로 해석 할 수 없습니다."

  24. 24

    TypeError : 'list'개체를 암시 적으로 str로 변환 할 수 없습니다.

  25. 25

    TypeError : 파일을 읽을 때 'str'개체를 호출 할 수 없습니다.

  26. 26

    TypeError : 'str'개체는 MySQL에서 호출 할 수 없습니다.

  27. 27

    TypeError : 'numpy.float64'개체를 호출 할 수 없습니까?

  28. 28

    TypeError : 계산을 인쇄 한 후 'float'개체를 호출 할 수 없습니다.

  29. 29

    계산기 오류 : TypeError : 'float'개체를 호출 할 수 없습니다.

뜨겁다태그

보관