Convert pandas data frame to series

It’s not smart enough to realize it’s still a “vector” in math terms. Say rather that it’s smart enough to recognize a difference in dimensionality. 🙂 I think the simplest thing you can do is select that row positionally using iloc, which gives you a Series with the columns as the new index and the values … Read more

Python Pandas: Get index of rows which column matches certain value

df.iloc[i] returns the ith row of df. i does not refer to the index label, i is a 0-based index. In contrast, the attribute index returns actual index labels, not numeric row-indices: or equivalently, You can see the difference quite clearly by playing with a DataFrame with a non-default index that does not equal to the row’s numerical position: If you want to use the index, … Read more

Selecting with complex criteria from pandas.DataFrame

Sure! Setup: We can apply column operations and get boolean Series objects: [Update, to switch to new-style .loc]: And then we can use these to index into the object. For read access, you can chain indices: but you can get yourself into trouble because of the difference between a view and a copy doing this for … Read more

Convert a Pandas DataFrame to a dictionary

The to_dict() method sets the column names as dictionary keys so you’ll need to reshape your DataFrame slightly. Setting the ‘ID’ column as the index and then transposing the DataFrame is one way to achieve this. to_dict() also accepts an ‘orient’ argument which you’ll need in order to output a list of values for each column. Otherwise, a dictionary of … Read more

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