slice

KeyError: “None of [['', '']] are in the [columns]” pandas python

主宰稳场 提交于 2019-11-30 20:10:17
I would like to slice two columns in my data frame. This is my code for doing this: import pandas as pd df = pd.read_csv('source.txt',header=0) cidf=df.loc[:,['vocab','sumCI']] print(cidf) This is a sample of data: ID vocab sumCI sumnextCI new_diff 450 statu 3.0 0.0 3.0 391 provid 4.0 1.0 3.0 382 prescript 3.0 0.0 3.0 300 lymphoma 2.0 0.0 2.0 405 renew 2.0 0.0 2.0 **Firstly I got this error: ** KeyError: “None of [['', '']] are in the [columns]”' What I have tried: I tried putting a header with index 0 while reading the file, I tried to rename columns with this code: df.rename(columns=df.iloc

Making A Graphic Pie Chart In C#

江枫思渺然 提交于 2019-11-30 19:37:39
I'm trying to write a Windows Application that shows a pie chart with seven unequal slices (25%, 20%, 18%, 17%, 10%, 10%, 10%) all of them will be colored differently. So far I have made Pens and Brushes with colors attached and drawn a circle. This is what I have so far private void Form1_Paint(object sender, PaintEventArgs e) { this.BackColor = Color.White; this.Text = "Pie Chart"; this.Width = 350; this.Height = 350; Pen black = new Pen(Color.Black); Pen blue = new Pen(Color.Blue); Pen green = new Pen(Color.Green); Pen red = new Pen(Color.Red); Pen orange = new Pen(Color.Orange); Pen pink =

How to pass an int slice to “$in” using mgo

爷,独闯天下 提交于 2019-11-30 19:14:16
问题 I'm having a bit of trouble creating a query using the bson functionality of mgo . I'm simply trying to do {'search_id': {'$in': [1,2,4,7,9]}} , but I can't work out how to do it in mgo . I have a slice of int s, and tried passing that directly: toRemove := []int{1,2,4,7,9} err = coll.Remove(bson.M{"search_id": bson.M{"$in": toRemove}}) I saw another post which suggested I needed to use []interface{} , but that doesn't work either: toRemoveI := make([]interface{}, len(toRemove)) for idx, val

What does 'result[::-1]' mean?

最后都变了- 提交于 2019-11-30 18:37:51
I am just coming cross the following python code which confuses me a bit: res = self.result[::-1].encode('hex') The encode stuff is pretty clear, it should be represented as hex value. However, what does this self.result[::-1] mean, especially the colons? It represents the 'slice' to take from the result. The first element is the starting position, the second is the end (non-inclusive) and the third is the step. An empty value before/after a colon indicates you are either starting from the beginning ( s[:3] ) or extending to the end ( s[3:] ). You can include actual numbers here as well, but

Algorithm for slicing planes (in place) out of an array of RGB values

左心房为你撑大大i 提交于 2019-11-30 15:21:10
问题 I've got a flat array of byte RGB values that goes R1 G1 B1 R2 G2 B2 R3 G3 B3 ... Rn Gn Bn . So my data looks like: char imageData[WIDTH * HEIGHT * 3]; But I want to pass a WIDTH*HEIGHT array to an existing C library that expects a single plane of this data. That would be a sequence of just the R values (or just the G, or just the B). It's easy enough to allocate a new array and copy the data (duh). But the images are very large. If it weren't a C library but took some kind of iteration

Python: an efficient way to slice a list with a index list

瘦欲@ 提交于 2019-11-30 15:17:07
问题 I wish to know an efficient way and code saving to slice a list of thousand of elements example: b = ["a","b","c","d","e","f","g","h"] index = [1,3,6,7] I wish a result like as: c = ["b","d","g","h"] 回答1: The most direct way to do this with lists is to use a list comprehension: c = [b[i] for i in index] But, depending on exactly what your data looks like and what else you need to do with it, you could use numpy arrays - in which case: c = b[index] would do what you want, and would avoid the

How to slice a deque? [duplicate]

ⅰ亾dé卋堺 提交于 2019-11-30 14:33:48
问题 This question already has answers here : Use slice notation with collections.deque (6 answers) Closed 5 years ago . I've changed some code that used a list to using a deque. I can no longer slice into it, as I get the error: TypeError: sequence index must be integer, not 'slice' Here's a REPL that shows the problem. >>> import collections >>> d = collections.deque() >>> for i in range(3): ... d.append(i) ... >>> d deque([0, 1, 2]) >>> d[2:] Traceback (most recent call last): File "<stdin>",

Python: an efficient way to slice a list with a index list

梦想与她 提交于 2019-11-30 14:21:01
I wish to know an efficient way and code saving to slice a list of thousand of elements example: b = ["a","b","c","d","e","f","g","h"] index = [1,3,6,7] I wish a result like as: c = ["b","d","g","h"] The most direct way to do this with lists is to use a list comprehension: c = [b[i] for i in index] But, depending on exactly what your data looks like and what else you need to do with it, you could use numpy arrays - in which case: c = b[index] would do what you want, and would avoid the potential memory overhead for large slices - numpy arrays are stored more efficiently than lists, and slicing

Algorithm for slicing planes (in place) out of an array of RGB values

 ̄綄美尐妖づ 提交于 2019-11-30 14:05:50
I've got a flat array of byte RGB values that goes R1 G1 B1 R2 G2 B2 R3 G3 B3 ... Rn Gn Bn . So my data looks like: char imageData[WIDTH * HEIGHT * 3]; But I want to pass a WIDTH*HEIGHT array to an existing C library that expects a single plane of this data. That would be a sequence of just the R values (or just the G, or just the B). It's easy enough to allocate a new array and copy the data (duh). But the images are very large. If it weren't a C library but took some kind of iteration interface to finesse the "slicing" traversal, that would be great. But I can't edit the code I'm calling..

Python: single colon vs double colon

↘锁芯ラ 提交于 2019-11-30 12:59:53
What is the difference between single and double colon in this situation? data[0:,4] vs data[0::,4] women_only_stats = data[0::,4] == "female" men_only_stats = data[0::,4] != "female" I tried to replace data[0::,4] with data[0:,4] and I see no difference. Is there any difference in this or another case? data is 2-dimensional array with rows like ['1' '0' '3' 'Braund, Mr. Owen Harris' 'male' '22' '1' '0' 'A/5 21171' '7.25' '' 'S'] No , there is no difference. See the Python documentation for slice : From the docs: a[start:stop:step] The start and step arguments default to None. Slice objects