편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2020.01.31

    for문 질문드립니다.(2번째)


        import pandas as pd
        import pandas_datareader.data as web
        from pandas import Series, DataFrame
        import datetime
        import matplotlib.pylab as plt
        import numpy
        import seaborn as sns
    
        stock = {'msft' : 'MSFT','tencent' : '0700.HK'}
        start = datetime.datetime(2017, 1, 1)
        end = datetime.datetime(2020, 1, 27)
    
        for name, code in stock.items():
    
        foo = web.DataReader(code, 'yahoo', start, end)
        bar = name + '_close'
        foo.rename(columns = {'Adj Close': bar}, inplace = True)
        stock_price = pd.concat(foo[bar], axis = 1)
    

    ----아래오류

    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-104-3bd2e868540e> in <module>
          8     bar = name + '_close'
          9     foo.rename(columns = {'Adj Close': bar}, inplace = True)
    ---> 10     stock_price = pd.concat(foo[bar], axis = 1)
    
    C:\conda\lib\site-packages\pandas\core\reshape\concat.py in concat(objs, axis, join, join_axes, ignore_index, keys, levels, names, verify_integrity, sort, copy)
        253         verify_integrity=verify_integrity,
        254         copy=copy,
    --> 255         sort=sort,
        256     )
        257 
    
    C:\conda\lib\site-packages\pandas\core\reshape\concat.py in __init__(self, objs, axis, join, join_axes, keys, levels, names, ignore_index, verify_integrity, copy, sort)
        282                 "first argument must be an iterable of pandas "
        283                 "objects, you passed an object of type "
    --> 284                 '"{name}"'.format(name=type(objs).__name__)
        285             )
        286 
    
    TypeError: first argument must be an iterable of pandas objects, you passed an object of type "Series"
    ----------------------
    

    해결방법이 무었일까요?

  • 프로필 Hyun Soo Choi님의 편집
    날짜2020.01.31

    for문 질문드립니다.(2번째 ㅠ)


    import pandas as pd
    import pandas_datareader.data as web
    from pandas import Series, DataFrame
    import datetime
    import matplotlib.pylab as plt
    import numpy
    import seaborn as sns
    
    stock = {'msft' : 'MSFT','tencent' : '0700.HK'}
    start = datetime.datetime(2017, 1, 1)
    end = datetime.datetime(2020, 1, 27)
    
    for name, code in stock.items():
    
    foo = web.DataReader(code, 'yahoo', start, end)
    bar = name + '_close'
    foo.rename(columns = {'Adj Close': bar}, inplace = True)
    stock_price = pd.concat(foo[bar], axis = 1)
    

    ----아래오류

    TypeError Traceback (most recent call last) in 8 bar = name + '_close' 9 foo.rename(columns = {'Adj Close': bar}, inplace = True) ---> 10 stock_price = pd.concat(foo[bar], axis = 1)

    C:\conda\lib\site-packages\pandas\core\reshape\concat.py in concat(objs, axis, join, join_axes, ignore_index, keys, levels, names, verify_integrity, sort, copy) 253 verify_integrity=verify_integrity, 254 copy=copy, --> 255 sort=sort, 256 ) 257

    C:\conda\lib\site-packages\pandas\core\reshape\concat.py in init(self, objs, axis, join, join_axes, keys, levels, names, ignore_index, verify_integrity, copy, sort) 282 "first argument must be an iterable of pandas " 283 "objects, you passed an object of type " --> 284 '"{name}"'.format(name=type(objs).name) 285 ) 286

    TypeError: first argument must be an iterable of pandas objects, you passed an object of type "Series"

    해결방법이 무었일까요 ㅠㅠㅠㅠ