2014-11-11 2 views
1

나는 OAuth2가 나를 위해 예상대로 작동하는지 확인하기 위해 Hello Analytics 튜토리얼을 통해 작업했지만 pandas.io.ga 모듈에 어떤 행운이 없다. 예상대로pandas.io.ga 나를 위해 일하지 않는다

In [1]: from pandas.io import ga 

In [2]: df = ga.read_ga("pageviews", "pagePath", "2014-07-08") 
/usr/local/lib/python2.7/dist-packages/pandas/core/index.py:1162: FutureWarning: using '-' to provide set differences 
with Indexes is deprecated, use .difference() 
"use .difference()",FutureWarning) 
/usr/local/lib/python2.7/dist-packages/pandas/core/index.py:1147: FutureWarning: using '+' to provide set union with 
Indexes is deprecated, use '|' or .union() 
"use '|' or .union()",FutureWarning) 
--------------------------------------------------------------------------- 
TypeError         Traceback (most recent call last) 
<ipython-input-2-b5343faf9ae6> in <module>() 
----> 1 df = ga.read_ga("pageviews", "pagePath", "2014-07-08") 

/usr/local/lib/python2.7/dist-packages/pandas/io/ga.pyc in read_ga(metrics, dimensions, start_date, **kwargs) 
    105  reader = GAnalytics(**reader_kwds) 
    106  return reader.get_data(metrics=metrics, start_date=start_date, 
--> 107       dimensions=dimensions, **kwargs) 
    108 
    109 

/usr/local/lib/python2.7/dist-packages/pandas/io/ga.pyc in get_data(self, metrics, start_date, end_date, dimensions, 
segment, filters, start_index, max_results, index_col, parse_dates, keep_date_col, date_parser, na_values, converters, 
sort, dayfirst, account_name, account_id, property_name, property_id, profile_name, profile_id, chunksize) 
    293 
    294   if chunksize is None: 
--> 295    return _read(start_index, max_results) 
    296 
    297   def iterator(): 

/usr/local/lib/python2.7/dist-packages/pandas/io/ga.pyc in _read(start, result_size) 
    287           dayfirst=dayfirst, 
    288           na_values=na_values, 
--> 289           converters=converters, sort=sort) 
    290    except HttpError as inst: 
    291     raise ValueError('Google API error %s: %s' % (inst.resp.status, 

/usr/local/lib/python2.7/dist-packages/pandas/io/ga.pyc in _parse_data(self, rows, col_info, index_col, parse_dates, 
keep_date_col, date_parser, dayfirst, na_values, converters, sort) 
    313         keep_date_col=keep_date_col, 
    314         converters=converters, 
--> 315         header=None, names=col_names)) 
    316 
    317   if isinstance(sort, bool) and sort: 

/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.pyc in _read(filepath_or_buffer, kwds) 
    237 
    238  # Create the parser. 
--> 239  parser = TextFileReader(filepath_or_buffer, **kwds) 
    240 
    241  if (nrows is not None) and (chunksize is not None): 

/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.pyc in __init__(self, f, engine, **kwds) 
    551    self.options['has_index_names'] = kwds['has_index_names'] 
    552 
--> 553   self._make_engine(self.engine) 
    554 
    555  def _get_options_with_defaults(self, engine): 

/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.pyc in _make_engine(self, engine) 
    694    elif engine == 'python-fwf': 
    695     klass = FixedWidthFieldParser 
--> 696    self._engine = klass(self.f, **self.options) 
    697 
    698  def _failover_to_python(self): 

/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.pyc in __init__(self, f, **kwds) 
    1412   if not self._has_complex_date_col: 
    1413    (index_names, 
-> 1414    self.orig_names, self.columns) = self._get_index_name(self.columns) 
    1415    self._name_processed = True 
    1416    if self.index_names is None: 

/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.pyc in _get_index_name(self, columns) 
    1886    # Case 2 
    1887    (index_name, columns_, 
-> 1888    self.index_col) = _clean_index_names(columns, self.index_col) 
    1889 
    1890   return index_name, orig_names, columns 

/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.pyc in _clean_index_names(columns, index_col) 
    2171      break 
    2172   else: 
-> 2173    name = cp_cols[c] 
    2174    columns.remove(name) 
    2175    index_names.append(name) 

TypeError: list indices must be integers, not Index 

OAuth2를가 작동하고 난 단지 데모 변수로 이러한 매개 변수를 사용했다 - 쿼리 자체가 쓰레기입니다 : 특히,이 오류와 함께 붙어있다. 기본적으로 오류의 출처를 파악할 수 없으며 포인터가 가지고있는 모든 점을 이해할 수 있습니다.

감사합니다.

솔루션 (일종의)

이 내가 무엇을 액세스하거나하기 위해 노력하고있어 데이터와 관련이있다 확실하지만, 내가지고있어 문제가되는 인덱스 유형 오류하여 index_col 변수에서 발생하지 않음 pandas.io.ga.GDataReader.get_data()는 pandas.core.index.Index 유형입니다. 이것은 넘어지는 _parse_data()의 pandas.io.parsers._read()에 공급됩니다. 나는 이것을 이해하지 못한다. 그러나 그것은 나를위한 단점이다.

index_col = _clean_index(list(dimensions), parse_dates).tolist() 

모든 것이 버터 지금처럼 부드럽게,하지만 난이 중단 될 수 있습니다 의심 - 다른 사람이 문제가되는 경우 - I가 ga.py의 라인 (270)을 편집 한 수정으로

다른 상황의 것들 ...

답변

1

불행히도,이 모듈은 실제로 문서화되지 않았고 오류가 항상 의미있는 것은 아닙니다. account_name, property_nameprofile_name (profile_name은 온라인 버전의 경우 View입니다.) 그런 다음 dimensionsmetrics을 포함시키고 client_secrets.jsonpandas.io 디렉토리에 있는지 확인하십시오. 예 :

ga.read_ga(account_name=account_name, 
      property_name=property_name, 
      profile_name=profile_name, 
      dimensions=['date', 'hour', 'minute'], 
      metrics=['pageviews'], 
      start_date=start_date, 
      end_date=end_date, 
      index_col=0, 
      parse_dates={'datetime': ['date', 'hour', 'minute']}, 
      date_parser=lambda x: datetime.strptime(x, '%Y%m%d %H %M'), 
      max_results=max_results) 

또한 팬더와 GA에 대한 단계 blog post로 내 최근 단계를 보라.

+1

아, 그게 훨씬 좋습니다! 단순히 index_col = 키워드를 전달하면 일이 잘 진행됩니다. 내가하지 않으면 (즉, 예제 코드에서와 같이 인수를 전달하지 마십시오.) 필자가 위의 편집 작업에 넣은 "솔루션"이 작동하고 날짜가 맨 위에있는 다중 인덱스를 사용하여 DataFrame 객체가 만들어집니다 수평. – tim

관련 문제