series

Dynamic Flot graph - show hide series by clicking on legend text or box on graph

回眸只為那壹抹淺笑 提交于 2019-11-27 03:14:39
问题 I am working on dynamic flot graph with 3 series. My need is to hide/show series when clicked on legend. I have seen different examples that will work fine for static graphs but for dynamic graph, even it works first time but when graph is updated with new data values then everything is displaying with default options. once I hide the series, I want it to be hided until I click again to show it. 回答1: Here's a quick example I put together for you. somePlot = null; togglePlot = function

Convert pandas Series to DataFrame

余生长醉 提交于 2019-11-27 03:00:44
I have a Pandas series sf: email email1@email.com [1.0, 0.0, 0.0] email2@email.com [2.0, 0.0, 0.0] email3@email.com [1.0, 0.0, 0.0] email4@email.com [4.0, 0.0, 0.0] email5@email.com [1.0, 0.0, 3.0] email6@email.com [1.0, 5.0, 0.0] And I would like to transform it to the following DataFrame: index | email | list _____________________________________________ 0 | email1@email.com | [1.0, 0.0, 0.0] 1 | email2@email.com | [2.0, 0.0, 0.0] 2 | email3@email.com | [1.0, 0.0, 0.0] 3 | email4@email.com | [4.0, 0.0, 0.0] 4 | email5@email.com | [1.0, 0.0, 3.0] 5 | email6@email.com | [1.0, 5.0, 0.0] I found

How can I create a series of months to join sparse data to?

谁说我不能喝 提交于 2019-11-27 03:00:26
问题 I think this is a pretty common issue, but I don't know what the process is called, so I'll describe it with an example. The concept is that I want to join a sparse dataset to a complete series, such as the days of the week, months of the year, or any ordered set (for example, for ranking). Empty positions in the sparse data will show as NULL alongside the complete series. Let's say I run the following query in SQL Server to find out monthly sales. SELECT YEAR([timestamp]), MONTH([timestamp])

Pandas selecting by label sometimes return Series, sometimes returns DataFrame

你。 提交于 2019-11-27 02:59:36
In Pandas, when I select a label that only has one entry in the index I get back a Series, but when I select an entry that has more then one entry I get back a data frame. Why is that? Is there a way to ensure I always get back a data frame? In [1]: import pandas as pd In [2]: df = pd.DataFrame(data=range(5), index=[1, 2, 3, 3, 3]) In [3]: type(df.loc[3]) Out[3]: pandas.core.frame.DataFrame In [4]: type(df.loc[1]) Out[4]: pandas.core.series.Series Granted that the behavior is inconsistent, but I think it's easy to imagine cases where this is convenient. Anyway, to get a DataFrame every time,

Adding a column thats result of difference in consecutive rows in pandas

点点圈 提交于 2019-11-27 00:39:57
Lets say I have a dataframe like this A B 0 a b 1 c d 2 e f 3 g h 0,1,2,3 are times, a, c, e, g is one time series and b, d, f, h is another time series. I need to be able to add two columns to the orignal dataframe which is got by computing the differences of consecutive rows for certain columns. So i need something like this A B dA 0 a b (a-c) 1 c d (c-e) 2 e f (e-g) 3 g h Nan I saw something called diff on the dataframe/series but that does it slightly differently as in first element will become Nan. Use shift . df['dA'] = df['A'] - df['A'].shift(-1) You could use diff and pass -1 as the

Is there a simple way to change a column of yes/no to 1/0 in a Pandas dataframe?

妖精的绣舞 提交于 2019-11-27 00:22:47
问题 I read a csv file into a pandas dataframe, and would like to convert the columns with binary answers from strings of yes/no to integers of 1/0. Below, I show one of such columns ("sampleDF" is the pandas dataframe). In [13]: sampleDF.housing[0:10] Out[13]: 0 no 1 no 2 yes 3 no 4 no 5 no 6 no 7 no 8 yes 9 yes Name: housing, dtype: object Help is much appreciated! 回答1: method 1 sample.housing.eq('yes').mul(1) method 2 pd.Series(np.where(sample.housing.values == 'yes', 1, 0), sample.index)

Finding the intersection between two series in Pandas

戏子无情 提交于 2019-11-26 22:45:49
问题 I have two series s1 and s2 in pandas/python and want to compute the intersection i.e. where all of the values of the series are common. How would I use the concat function to do this? I have been trying to work it out but have been unable to (I don't want to compute the intersection on the indices of s1 and S2, but on the values). Thanks in advance. 回答1: Place both series in Python's set container then use the set intersection method: s1.intersection(s2) and then transform back to list if

Combining two Series into a DataFrame in pandas

有些话、适合烂在心里 提交于 2019-11-26 21:11:19
I have two Series s1 and s2 with the same (non-consecutive) indices. How do I combine s1 and s2 to being two columns in a DataFrame and keep one of the indices as a third column? 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 s2 A 1 3 B 2 4 In [4]: pd.concat([s1, s2], axis=1).reset_index() Out[4]: index s1 s2 0 A 1 3 1 B 2 4

Convert Pandas series containing string to boolean

雨燕双飞 提交于 2019-11-26 20:23:08
问题 I have a DataFrame named df as Order Number Status 1 1668 Undelivered 2 19771 Undelivered 3 100032108 Undelivered 4 2229 Delivered 5 00056 Undelivered I would like to convert the Status column to boolean ( True when Status is Delivered and False when Status is Undelivered) but if Status is neither 'Undelivered' neither 'Delivered' it should be considered as NotANumber or something like that. I would like to use a dict d = { 'Delivered': True, 'Undelivered': False } so I could easily add other

Pandas pd.Series.isin performance with set versus array

倖福魔咒の 提交于 2019-11-26 20:13:54
In Python generally, membership of a hashable collection is best tested via set . We know this because the use of hashing gives us O(1) lookup complexity versus O(n) for list or np.ndarray . In Pandas, I often have to check for membership in very large collections. I presumed that the same would apply, i.e. checking each item of a series for membership in a set is more efficient than using list or np.ndarray . However, this doesn't seem to be the case: import numpy as np import pandas as pd np.random.seed(0) x_set = {i for i in range(100000)} x_arr = np.array(list(x_set)) x_list = list(x_set)