google analytics - pandas.io.ga not working for me -


so have worked through hello analytics tutorial confirm oauth2 working expected me, i'm not having luck pandas.io.ga module. in particular, stuck error:

in [1]: 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 '-' provide set differences  indexes deprecated, use .difference() "use .difference()",futurewarning) /usr/local/lib/python2.7/dist-packages/pandas/core/index.py:1147: futurewarning: using '+' provide set union  indexes 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 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 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) , sort:  /usr/local/lib/python2.7/dist-packages/pandas/io/parsers.pyc in _read(filepath_or_buffer, kwds)     237      238     # create parser. --> 239     parser = textfilereader(filepath_or_buffer, **kwds)     240      241     if (nrows not none) , (chunksize 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 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 integers, not index 

oauth2 working expected , have used these parameters demo variables--the query junk. basically, cannot figure out error coming from, , appreciate pointers 1 may have.

thanks!

solution (sort of)

not sure if has data i'm trying access or what, offending index type error i'm getting arises the index_col variable in pandas.io.ga.gdatareader.get_data() of type pandas.core.index.index. fed pandas.io.parsers._read() in _parse_data() falls over. don't understand this, breaking point me.

as fix--if else having problem--i have edited line 270 of ga.py to:

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

and smooth butter, suspect may break things in other situations...

unfortunately, module isn't documented , errors aren't meaningful. include account_name, property_name , profile_name (profile_name view in online version). include dimensions , metrics interested in. make sure client_secrets.json in pandas.io directory. example:

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) 

also have @ recent step step blog post ga pandas.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -