series

Work with a row in a pandas dataframe without incurring chain indexing (not coping just indexing)

人走茶凉 提交于 2019-12-24 08:33:23
问题 My data is organized in a dataframe: import pandas as pd import numpy as np data = {'Col1' : [4,5,6,7], 'Col2' : [10,20,30,40], 'Col3' : [100,50,-30,-50], 'Col4' : ['AAA', 'BBB', 'AAA', 'CCC']} df = pd.DataFrame(data=data, index = ['R1','R2','R3','R4']) Which looks like this (only much bigger): Col1 Col2 Col3 Col4 R1 4 10 100 AAA R2 5 20 50 BBB R3 6 30 -30 AAA R4 7 40 -50 CCC My algorithm loops through this table rows and performs a set of operations. For cleaness/lazyness sake, I would like

R: Continuous futures working backward

萝らか妹 提交于 2019-12-24 08:33:19
问题 I want to create a continuous futures series, that is to eliminate a gap between two series. First thing I want is to download all individual contracts from the beginning to the now, the syntax is always the same: Quandl("CME/INSTRUMENT_MONTHCODE_YEAR") 1.INSTRUMENT is GC (gold) in this case 2.MONTHCODE is G J M Q V Z 3.YEAR is from 1975 to 2017 (the actual contract) With the data, I start working from the last contract, in this case "CME/GCG1975" and with the next contract "CME/GCJ1975".

Python 2.7 - Calculate quantiles per row

做~自己de王妃 提交于 2019-12-24 08:03:09
问题 I have a pandas series like this: 0 1787 1 4789 2 1350 3 1476 4 0 5 747 6 307 7 147 8 221 9 -88 10 9374 11 264 12 1109 13 502 14 360 15 194 16 4073 17 2317 18 -221 20 0 21 16 22 106 29 105 30 4189 31 171 32 42 I want to create 4 one hot encoded variables that indicates which value per row is on which quartile, dividing the series into 4 quartiles. It would be something like this: 0 1787 Q1 Q2 Q3 Q4 1 4789 0 0 0 0 2 1350 0 0 0 1 3 1476 1 0 0 0 4 0 0 1 0 0 5 747 0 0 1 0 6 307 1 0 1 0 7 147 0 1

Deleting empty Series out of Graph (with VBA)

前提是你 提交于 2019-12-24 05:23:07
问题 I am trying to remove all empty series out of an Excel graph. Dim isEmptySeries As Boolean For Series = 1 To .SeriesCollection.count .SeriesCollection(Series).ApplyDataLabels Type:=xlDataLabelsShowValue, AutoText:=True, LegendKey:=False isEmptySeries = True For i = 1 To .SeriesCollection(Series).points.count If .SeriesCollection(Series).points(i).DataLabel.Text = 0 Then .SeriesCollection(Series).points(i).HasDataLabel = False Else isEmptySeries = False .SeriesCollection(Series).points(i)

powershell cannot add more than one legend entry (series) to an excel chart

a 夏天 提交于 2019-12-23 17:53:22
问题 I have a problem adding more than one series to the seriescollection in excels chart object through powershell here is my code: [threading.thread]::CurrentThread.CurrentCulture = 'en-US' $excel = New-Object -comobject Excel.Application $workbook = $excel.workbooks.add() $datasheet = $workbook.Worksheets.Item(2) $chartsheet = $workbook.Worksheets.Item(1) [datetime] $startDate = "2012-11-29 00:00:00" [datetime] $finishDate = "2012-12-07 00:00:00" [datetime] $dayCounter = $startDate $startRow =

Python Pandas Series failure datetime

有些话、适合烂在心里 提交于 2019-12-23 08:35:19
问题 I think that this has to be a failure of pandas, having a pandas Series (v.18.1 and 19 too), if I assign a date to the Series, the first time it is added as int (error), the second time it is added as datetime(correct), I can not understand the reason. For instance with this code: import datetime as dt import pandas as pd series = pd.Series(list('abc')) date = dt.datetime(2016, 10, 30, 0, 0) series["Date_column"] =date print("The date is {} and the type is {}".format(series["Date_column"],

d3 javascript series chart

家住魔仙堡 提交于 2019-12-23 06:40:13
问题 I am trying to create this particular d3 application where a series of data can be dynamically displayed like this. Each segment contains two pieces of data. The first step is to print the circles so there is sufficient space between the series but also the largest circle is always under the smaller circle. // version 3 -- with correct labels and legend-- http://jsfiddle.net/0ht35rpb/33/ //******version 2 fiddle****** http://jsfiddle.net/1oka61mL/10/ -- How to set the diagonal labels properly

Using Boolean Logic to clean DF in pandas

不打扰是莪最后的温柔 提交于 2019-12-23 05:13:07
问题 df shape square shape circle animal NaN NaN dog NaN cat NaN fish color red color blue desired_df shape square shape circle animal dog animal cat animal fish color red color blue I have a df contains information that needs to be normalized. I have noticed a pattern that indicates how to join the columns and normalize the data. If in Col1 != NaN and Col2 == NaN and directly in the following row Col1 == NaN and Col2 != NaN, then then values from Col1 and Col2 should be joined. This continues

Pandas: pad series on top or bottom

断了今生、忘了曾经 提交于 2019-12-23 03:32:21
问题 This turned out to be non-trivial for me so I wanted to check if others have a simple solution for this: Suppose I have an arbitrary number (say 3) of pd.Series : which look like: first = pd.Series(range(5)) second = pd.Series(range(7)) third = pd.Series(range(6)) I'd like to make them all of the same length (7 -- which is the largest length) and pad the shorter ones with np.nan s either at the top (optionally at the bottom) so that first looks like: nan nan 0 1 2 3 4 and so on. 回答1: You

Return the unmatched rows from the regex pattern

ぐ巨炮叔叔 提交于 2019-12-22 18:41:33
问题 If I have a pandas dataframe that looks like this: Sequence Rating 0 HYHIVQKF 1 1 YGEIFEKF 2 2 TYGGSWKF 3 3 YLESFYKF 4 4 YYNTAVKL 5 5 WPDVIHSF 6 This is the code that I am using the return the rows that match the following pattern: \b.[YF]\w+[LFI]\b pat = r'\b.[YF]\w+[LFI]\b' new_df.Sequence.str.contains(pat) new_df[new_df.Sequence.str.contains(pat)] The above code is returning the rows that match the pattern, but what can I use to return the unmatched rows? Expected Output: Sequence Rating 1