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

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

Python: pandas merge multiple dataframes

Below, is the most clean, comprehensible way of merging multiple dataframe if complex queries aren’t involved. Just simply merge with DATE as the index and merge using OUTER method (to get all the data). Now, basically load all the files you have as data frame into a list. And, then merge the files using merge or reduce function. Note: you can add as … Read more

Combine two columns of text in pandas dataframe

If both columns are strings, you can concatenate them directly: If one (or both) of the columns are not string typed, you should convert it (them) first, Beware of NaNs when doing this! If you need to join multiple string columns, you can use agg: Where “-” is the separator.

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