Why am I seeing “TypeError: string indices must be integers”?

item is most likely a string in your code; the string indices are the ones in the square brackets, e.g., gravatar_id. So I’d first check your data variable to see what you received there; I guess that data is a list of strings (or at least a list containing at least one string) while it should be a list of dictionaries.

how to sort pandas dataframe from one column

Use sort_values to sort the df by a specific column’s values: If you want to sort by two columns, pass a list of column labels to sort_values with the column labels ordered according to sort priority. If you use df.sort_values([‘2’, ‘0’]), the result would be sorted by column 2 then column 0. Granted, this does not really make sense for this example because … Read more

How to define a two-dimensional array?

You’re technically trying to index an uninitialized array. You have to first initialize the outer list with lists before adding items; Python calls this “list comprehension”. #You can now add items to the list: Note that the matrix is “y” address major, in other words, the “y index” comes before the “x index”. Although you … Read more

Iterating over dictionaries using ‘for’ loops

key is just a variable name. will simply loop over the keys in the dictionary, rather than the keys and values. To loop over both key and value you can use the following: For Python 3.x: For Python 2.x: To test for yourself, change the word key to poop. In Python 3.x, iteritems() was replaced with simply items(), which returns a set-like … Read more

Understanding slice notation

It’s pretty simple really: There is also the step value, which can be used with any of the above: The key point to remember is that the :stop value represents the first value that is not in the selected slice. So, the difference between stop and start is the number of elements selected (if step is 1, the default). The other feature is that start or stop may be a negative number, which … Read more

sphinx.ext.autodoc: Keeping names of constants in signature

You probably have to override the signature by hand in the reST file. It’s hard to come up with a better answer. Autodoc imports the modules it documents, so all module-level code (including default function arguments) is executed. See also these similar questions: here and here. Update: I just realized that there is another option. You can override the signature … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)