series

Compute the running (cumulative) maximum for a series in pandas

依然范特西╮ 提交于 2019-11-30 22:01:28
Given: d = { 'High': [954, 953, 952, 955, 956, 952, 951, 950, ] } df = pandas.DataFrame(d) I want to add another column which is the max at each index from the beginning. For example the desired column would be: 'Max': [954, 954, 954, 955, 956, 956, 956, 956] I tried with a pandas rolling function but the window cannot be dynamic it seems Use cummax df.High.cummax() 0 954 1 954 2 954 3 955 4 956 5 956 6 956 7 956 Name: High, dtype: int64 df['Max'] = df.High.cummax() df 来源: https://stackoverflow.com/questions/39498729/compute-the-running-cumulative-maximum-for-a-series-in-pandas

pandas create a series with n elements (sequential or randbetween)

霸气de小男生 提交于 2019-11-30 19:17:17
I am trying to create a pandas series. One column of the series should contain n sequential numbers. [1, 2, 3, ..., n] One column should contain random numbers between k and k+100 . One column should contain random selection between strings in a list. ['A', 'B', 'C', ... 'Z'] jezrael There can be a lot of solutions. In the comments of the code block ( # ) you will find a few links for more information: import pandas as pd import numpy as np import random import string k = 5 N = 10 #http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.randint.html #http://stackoverflow.com/a/2257449

Compute the running (cumulative) maximum for a series in pandas

独自空忆成欢 提交于 2019-11-30 17:42:24
问题 Given: d = { 'High': [954, 953, 952, 955, 956, 952, 951, 950, ] } df = pandas.DataFrame(d) I want to add another column which is the max at each index from the beginning. For example the desired column would be: 'Max': [954, 954, 954, 955, 956, 956, 956, 956] I tried with a pandas rolling function but the window cannot be dynamic it seems 回答1: Use cummax df.High.cummax() 0 954 1 954 2 954 3 955 4 956 5 956 6 956 7 956 Name: High, dtype: int64 df['Max'] = df.High.cummax() df 来源: https:/

convert timestamp to datetime.datetime in pandas.Series

寵の児 提交于 2019-11-30 16:06:38
问题 I have pandas Series where index is a list of integer (timestamp), how can I convert them to datetime.datetime (with timezone) more efficient than below raw conversion? pd.Series(data=s.values, index=map(lambda x:datetime.datetime.fromtimestamp(x,tz=utc), s.index)) 回答1: In [49]: s = Series(range(10)) Using to_datetime , you can supply a unit to select what the meaning of the integers. In [50]: pd.to_datetime(s,unit='s') Out[50]: 0 1970-01-01 00:00:00 1 1970-01-01 00:00:01 2 1970-01-01 00:00

subclasses of pandas' object work differently from subclass of other object?

雨燕双飞 提交于 2019-11-30 15:39:59
问题 I am trying to create a subclass of a Pandas data structure to substitute, in my code, a subclass of a dict with a subclass of a Series , I don't understand why this example code doesn't work from pandas import Series class Support(Series): def supportMethod1(self): print 'I am support method 1' def supportMethod2(self): print 'I am support method 2' class Compute(object): supp=None def test(self): self.supp() class Config(object): supp=None @classmethod def initializeConfig(cls): cls.supp

Adding new HighChart Series

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 15:07:10
At this code javascrip give an error $.each(JSON, function(i, array) { chart.series[i].name = array.teamName; chart.series[i].setData(array.teamPower, true); }); I must define the chart.series[i] because it say "Cannot set property 'name' of undefined" but i can't find a way in order to do this. Because it fonction runs with requestData so it came after chart determine with options function showGraph() { chart = new Highcharts.Chart(option); } chart: { renderTo: 'graphicShow', type: 'spline', events: { load: requestData } } ...in option... title: { text: 'Power %' }, series: [] ... You need to

subclasses of pandas' object work differently from subclass of other object?

感情迁移 提交于 2019-11-30 14:48:47
I am trying to create a subclass of a Pandas data structure to substitute, in my code, a subclass of a dict with a subclass of a Series , I don't understand why this example code doesn't work from pandas import Series class Support(Series): def supportMethod1(self): print 'I am support method 1' def supportMethod2(self): print 'I am support method 2' class Compute(object): supp=None def test(self): self.supp() class Config(object): supp=None @classmethod def initializeConfig(cls): cls.supp=Support() @classmethod def setConfig1(cls): Compute.supp=cls.supp.supportMethod1 @classmethod def

Pandas Series of lists to one series

怎甘沉沦 提交于 2019-11-30 11:01:05
I have a Pandas Series of lists of strings: 0 [slim, waist, man] 1 [slim, waistline] 2 [santa] As you can see, the lists vary by length. I want an efficient way to collapse this into one series 0 slim 1 waist 2 man 3 slim 4 waistline 5 santa I know I can break up the lists using series_name.split(' ') But I am having a hard time putting those strings back into one list. Thanks! You are basically just trying to flatten a nested list here. You should just be able to iterate over the elements of the series: slist =[] for x in series: slist.extend(x) or a slicker (but harder to understand) list

Python Pandas removing substring using another column

落花浮王杯 提交于 2019-11-30 08:28:51
问题 I've tried searching around and can't figure out an easy way to do this, so I'm hoping your expertise can help. I have a pandas data frame with two columns import numpy as np import pandas as pd pd.options.display.width = 1000 testing = pd.DataFrame({'NAME':[ 'FIRST', np.nan, 'NAME2', 'NAME3', 'NAME4', 'NAME5', 'NAME6'], 'FULL_NAME':['FIRST LAST', np.nan, 'FIRST LAST', 'FIRST NAME3', 'FIRST NAME4 LAST', 'ANOTHER NAME', 'LAST NAME']}) which gives me FULL_NAME NAME 0 FIRST LAST FIRST 1 NaN NaN

Get first element of Series without knowing the index [duplicate]

强颜欢笑 提交于 2019-11-30 05:35:09
This question already has an answer here: Pandas - Get first row value of a given column 7 answers Is that any way that I can get first element of Seires without have information on index. For example,We have a Series import pandas as pd key='MCS096' SUBJECTS=pd.DataFrame({'ID':Series([146],index=[145]),\ 'study':Series(['MCS'],index=[145]),\ 'center':Series(['Mag'],index=[145]),\ 'initials':Series(['MCS096'],index=[145]) }) prints out SUBJECTS: print (SUBJECTS[SUBJECTS.initials==key]['ID']) 145 146 Name: ID, dtype: int64 How can I get the value here 146 without using index 145? Thank you very