Combining two Series into a DataFrame in pandas

I think concat is a nice way to do this. If they are present it uses the name attributes of the Series as the columns (otherwise it simply numbers them): In [1]: s1 = pd.Series([1, 2], index=[‘A’, ‘B’], name=”s1″) In [2]: s2 = pd.Series([3, 4], index=[‘A’, ‘B’], name=”s2″) In [3]: pd.concat([s1, s2], axis=1) Out[3]: s1 … Read more

What does axis in pandas mean?

It specifies the axis along which the means are computed. By default axis=0. This is consistent with the numpy.mean usage when axis is specified explicitly (in numpy.mean, axis==None by default, which computes the mean value over the flattened array) , in which axis=0 along the rows (namely, index in pandas), and axis=1 along the columns. … Read more

Convert data.frame columns from factors to characters

Just following on Matt and Dirk. If you want to recreate your existing data frame without changing the global option, you can recreate it with an apply statement: bob <- data.frame(lapply(bob, as.character), stringsAsFactors=FALSE) This will convert all variables to class “character”, if you want to only convert factors, see Marek’s solution below. As @hadley points … Read more

Remove pandas rows with duplicate indices

I would suggest using the duplicated method on the Pandas Index itself: df3 = df3[~df3.index.duplicated(keep=’first’)] While all the other methods work, .drop_duplicates is by far the least performant for the provided example. Furthermore, while the groupby method is only slightly less performant, I find the duplicated method to be more readable. Using the sample data … Read more

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