series

DataFrame correlation produces NaN although its values are all integers

ぐ巨炮叔叔 提交于 2020-01-02 03:53:30
问题 I have a dataframe df : df = pandas.DataFrame(pd.read_csv(loggerfile, header = 2)) values = df.as_matrix() df2 = pd.DataFrame.from_records(values, index = datetimeIdx, columns = Columns) EDIT: Now reading the data this way as suggested: df2 = pd.read_csv(loggerfile, header = None, skiprows = [0,1,2]) Sample: 0 1 2 3 4 5 6 7 8 \ 0 2014-03-19T12:44:32.695Z 1395233072695 703425 0 2 1 13 5 21 1 2014-03-19T12:44:32.727Z 1395233072727 703425 0 2 1 13 5 21 9 10 11 12 13 14 15 16 0 25 0 25 209 0 145

Which programming language or a library can process Infinite Series?

浪子不回头ぞ 提交于 2019-12-31 11:33:40
问题 Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence. For example, in Python it could look like: sum = 0 sign = -1.0 for i in range(1,Infinity,2): sign = -sign sum += sign / i then, sum must be math.pi/4 without doing any computations in the loop (because it's a well

Is it possible to append Series to rows of DataFrame without making a list first?

吃可爱长大的小学妹 提交于 2019-12-31 11:02:47
问题 I have some data I'm trying to organize into a DataFrame in Pandas . I was trying to make each row a Series and append it to the DataFrame . I found a way to do it by appending the Series to an empty list and then converting the list of Series to a DataFrame e.g. DF = DataFrame([series1,series2],columns=series1.index) This list to DataFrame step seems to be excessive. I've checked out a few examples on here but none of the Series preserved the Index labels from the Series to use them as

Is it possible to append Series to rows of DataFrame without making a list first?

独自空忆成欢 提交于 2019-12-31 11:02:36
问题 I have some data I'm trying to organize into a DataFrame in Pandas . I was trying to make each row a Series and append it to the DataFrame . I found a way to do it by appending the Series to an empty list and then converting the list of Series to a DataFrame e.g. DF = DataFrame([series1,series2],columns=series1.index) This list to DataFrame step seems to be excessive. I've checked out a few examples on here but none of the Series preserved the Index labels from the Series to use them as

largest element all lists in Panda Series

十年热恋 提交于 2019-12-31 05:04:26
问题 I have a pandas series say import pandas as pd a = pd.Series([ [1, 2, 3, 4, 5], [6, 7, 8, 3, 334], [333, 4, 5, 3, 4] ]) I want to find the largest element in all lists, which is 334, what is the easy way to do it? 回答1: Option 1 Only works if elements are actually list . This is because sum concatenates lists. This is also likely very slow. max(a.sum()) 334 Option 2 minimal two tiered application of max max(map(max, a)) 334 Option 3 Only works if all lists are same length np.max(a.tolist())

largest element all lists in Panda Series

点点圈 提交于 2019-12-31 05:04:15
问题 I have a pandas series say import pandas as pd a = pd.Series([ [1, 2, 3, 4, 5], [6, 7, 8, 3, 334], [333, 4, 5, 3, 4] ]) I want to find the largest element in all lists, which is 334, what is the easy way to do it? 回答1: Option 1 Only works if elements are actually list . This is because sum concatenates lists. This is also likely very slow. max(a.sum()) 334 Option 2 minimal two tiered application of max max(map(max, a)) 334 Option 3 Only works if all lists are same length np.max(a.tolist())

Pandas DataFrame - assign 1,0 values based on other column

牧云@^-^@ 提交于 2019-12-31 02:34:06
问题 I've got a dataframe containing country names & their percentage of energy output. I need to add a new column that assigns a 1 or 0, based on whether the country's energy output is above or below the median of energy output. Some dummy code is: import pandas as pd def answer(): df = pd.DataFrame({'name':['china', 'america', 'canada'], 'output': [33.2, 15.0, 5.0]}) df['newcol'] = df.where(df['output'] > df['output'].median(), 1, 0) return df['newcol'] answer() the code returns ValueError:

Common way to generate finite geometric series in MATLAB

醉酒当歌 提交于 2019-12-30 18:47:13
问题 Suppose I have some number a , and I want to get vector [ 1 , a , a^2 , ... , a^N ] . I use [ 1 , cumprod( a * ones( 1 , N - 1 ) ) ] code. What is the best (and propably efficient) way to do it? 回答1: What about a.^[0:N] ? 回答2: ThibThib's answer is absolutely correct, but it doesn't generalize very easily if a happens to a vector. So as a starting point: > a= 2 a = 2 > n= 3 n = 3 > a.^[0: n] ans = 1 2 4 8 Now you could also utilize the built-in function vander (although the order is different,

KeyError: 0 when accessing value in pandas series

江枫思渺然 提交于 2019-12-30 18:26:52
问题 In my script I have df['Time'] as shown below. 497 2017-08-06 11:00:00 548 2017-08-08 15:00:00 580 2017-08-10 04:00:00 646 2017-08-12 23:00:00 Name: Time, dtype: datetime64[ns] But when i do t1=pd.Timestamp(df['Time'][0]) I get an error like this : KeyError: 0 Do I need any type conversion here, if yes then how it can be fixed? 回答1: You're looking for df.iloc . df['Time'].iloc[0] df['Time'][0] would've worked if your series had an index beginning from 0 And if need scalar only use Series.iat:

KeyError: 0 when accessing value in pandas series

天涯浪子 提交于 2019-12-30 18:26:34
问题 In my script I have df['Time'] as shown below. 497 2017-08-06 11:00:00 548 2017-08-08 15:00:00 580 2017-08-10 04:00:00 646 2017-08-12 23:00:00 Name: Time, dtype: datetime64[ns] But when i do t1=pd.Timestamp(df['Time'][0]) I get an error like this : KeyError: 0 Do I need any type conversion here, if yes then how it can be fixed? 回答1: You're looking for df.iloc . df['Time'].iloc[0] df['Time'][0] would've worked if your series had an index beginning from 0 And if need scalar only use Series.iat: