message_type stringclasses 2 values | message stringlengths 2 232 ⌀ | message_id int64 0 1 | conversation_id int64 0 2.38k |
|---|---|---|---|
instruction | get a sum of 4d array `M` | 0 | 450 |
output | M.sum(axis=0).sum(axis=0) | 1 | 450 |
instruction | Convert a datetime object `dt` to microtime | 0 | 451 |
output | time.mktime(dt.timetuple()) + dt.microsecond / 1000000.0 | 1 | 451 |
instruction | select all rows in dataframe `df` where the values of column 'columnX' is bigger than or equal to `x` and smaller than or equal to `y` | 0 | 452 |
output | df[(x <= df['columnX']) & (df['columnX'] <= y)] | 1 | 452 |
instruction | sort a list of lists `L` by index 2 of the inner list | 0 | 453 |
output | sorted(L, key=itemgetter(2)) | 1 | 453 |
instruction | sort a list of lists `l` by index 2 of the inner list | 0 | 454 |
output | l.sort(key=(lambda x: x[2])) | 1 | 454 |
instruction | sort list `l` by index 2 of the item | 0 | 455 |
output | sorted(l, key=(lambda x: x[2])) | 1 | 455 |
instruction | sort a list of lists `list_to_sort` by indices 2,0,1 of the inner list | 0 | 456 |
output | sorted_list = sorted(list_to_sort, key=itemgetter(2, 0, 1)) | 1 | 456 |
instruction | find rows of 2d array in 3d numpy array 'arr' if the row has value '[[0, 3], [3, 0]]' | 0 | 457 |
output | np.argwhere(np.all(arr == [[0, 3], [3, 0]], axis=(1, 2))) | 1 | 457 |
instruction | From multiIndexed dataframe `data` select columns `a` and `c` within each higher order column `one` and `two` | 0 | 458 |
output | data.loc[:, (list(itertools.product(['one', 'two'], ['a', 'c'])))] | 1 | 458 |
instruction | select only specific columns 'a' and 'c' from a dataframe 'data' with multiindex columns | 0 | 459 |
output | data.loc[:, ([('one', 'a'), ('one', 'c'), ('two', 'a'), ('two', 'c')])] | 1 | 459 |
instruction | match a sharp, followed by letters (including accent characters) in string `str1` using a regex | 0 | 460 |
output | hashtags = re.findall('#(\\w+)', str1, re.UNICODE) | 1 | 460 |
instruction | Rename file from `src` to `dst` | 0 | 461 |
output | os.rename(src, dst) | 1 | 461 |
instruction | Get all texts and tags from a tag `strong` from etree tag `some_tag` using lxml | 0 | 462 |
output | print(etree.tostring(some_tag.find('strong'))) | 1 | 462 |
instruction | Serialize dictionary `data` and its keys to a JSON formatted string | 0 | 463 |
output | json.dumps({str(k): v for k, v in data.items()}) | 1 | 463 |
instruction | parse UTF-8 encoded HTML response `response` to BeautifulSoup object | 0 | 464 |
output | soup = BeautifulSoup(response.read().decode('utf-8')) | 1 | 464 |
instruction | delete file `filename` | 0 | 465 |
output | os.remove(filename) | 1 | 465 |
instruction | get the next value greatest to `2` from a list of numbers `num_list` | 0 | 466 |
output | min([x for x in num_list if x > 2]) | 1 | 466 |
instruction | Replace each value in column 'prod_type' of dataframe `df` with string 'responsive' | 0 | 467 |
output | df['prod_type'] = 'responsive' | 1 | 467 |
instruction | sort list `lst` with positives coming before negatives with values sorted respectively | 0 | 468 |
output | sorted(lst, key=lambda x: (x < 0, x)) | 1 | 468 |
instruction | get the date 6 months from today | 0 | 469 |
output | six_months = (date.today() + relativedelta(months=(+ 6))) | 1 | 469 |
instruction | get the date 1 month from today | 0 | 470 |
output | (date(2010, 12, 31) + relativedelta(months=(+ 1))) | 1 | 470 |
instruction | get the date 2 months from today | 0 | 471 |
output | (date(2010, 12, 31) + relativedelta(months=(+ 2))) | 1 | 471 |
instruction | calculate the date six months from the current date | 0 | 472 |
output | print((datetime.date.today() + datetime.timedelta(((6 * 365) / 12))).isoformat()) | 1 | 472 |
instruction | get a list of keys of dictionary `things` sorted by the value of nested dictionary key 'weight' | 0 | 473 |
output | sorted(list(things.keys()), key=lambda x: things[x]['weight'], reverse=True) | 1 | 473 |
instruction | get all the values from a numpy array `a` excluding index 3 | 0 | 474 |
output | a[np.arange(len(a)) != 3] | 1 | 474 |
instruction | delete all elements from a list `x` if a function `fn` taking value as parameter returns `0` | 0 | 475 |
output | [x for x in lst if fn(x) != 0] | 1 | 475 |
instruction | set dataframe `df` index using column 'month' | 0 | 476 |
output | df.set_index('month') | 1 | 476 |
instruction | read lines from a csv file `./urls-eu.csv` into a list of lists `arr` | 0 | 477 |
output | arr = [line.split(',') for line in open('./urls-eu.csv')] | 1 | 477 |
instruction | list comprehension that produces integers between 11 and 19 | 0 | 478 |
output | [i for i in range(100) if i > 10 if i < 20] | 1 | 478 |
instruction | Get only digits from a string `strs` | 0 | 479 |
output | """""".join([c for c in strs if c.isdigit()]) | 1 | 479 |
instruction | split a string `yas` based on tab '\t' | 0 | 480 |
output | re.split('\\t+', yas.rstrip('\t')) | 1 | 480 |
instruction | scalar multiply matrix `a` by `b` | 0 | 481 |
output | (a.T * b).T | 1 | 481 |
instruction | remove trailing newline in string "test string\n" | 0 | 482 |
output | 'test string\n'.rstrip() | 1 | 482 |
instruction | remove trailing newline in string 'test string \n\n' | 0 | 483 |
output | 'test string \n\n'.rstrip('\n') | 1 | 483 |
instruction | remove newline in string `s` | 0 | 484 |
output | s.strip() | 1 | 484 |
instruction | remove newline in string `s` on the right side | 0 | 485 |
output | s.rstrip() | 1 | 485 |
instruction | remove newline in string `s` on the left side | 0 | 486 |
output | s.lstrip() | 1 | 486 |
instruction | remove newline in string 'Mac EOL\r' | 0 | 487 |
output | 'Mac EOL\r'.rstrip('\r\n') | 1 | 487 |
instruction | remove newline in string 'Windows EOL\r\n' on the right side | 0 | 488 |
output | 'Windows EOL\r\n'.rstrip('\r\n') | 1 | 488 |
instruction | remove newline in string 'Unix EOL\n' on the right side | 0 | 489 |
output | 'Unix EOL\n'.rstrip('\r\n') | 1 | 489 |
instruction | remove newline in string "Hello\n\n\n" on the right side | 0 | 490 |
output | 'Hello\n\n\n'.rstrip('\n') | 1 | 490 |
instruction | split string `text` into chunks of 16 characters each | 0 | 491 |
output | re.findall('.{,16}\\b', text) | 1 | 491 |
instruction | Get a list comprehension in list of lists `X` | 0 | 492 |
output | [[X[i][j] for j in range(len(X[i]))] for i in range(len(X))] | 1 | 492 |
instruction | convert unicode string '\xd0\xbc\xd0\xb0\xd1\x80\xd0\xba\xd0\xb0' to byte string | 0 | 493 |
output | '\xd0\xbc\xd0\xb0\xd1\x80\xd0\xba\xd0\xb0'.encode('latin-1') | 1 | 493 |
instruction | split dataframe `df` where the value of column `a` is equal to 'B' | 0 | 494 |
output | df.groupby((df.a == 'B').shift(1).fillna(0).cumsum()) | 1 | 494 |
instruction | save json output from a url ‘http://search.twitter.com/search.json?q=hi’ to file ‘hi.json’ in Python 2 | 0 | 495 |
output | urllib.request.urlretrieve('http://search.twitter.com/search.json?q=hi', 'hi.json') | 1 | 495 |
instruction | Find indices of elements equal to zero from numpy array `x` | 0 | 496 |
output | numpy.where((x == 0))[0] | 1 | 496 |
instruction | flush output of python print | 0 | 497 |
output | sys.stdout.flush() | 1 | 497 |
instruction | convert `i` to string | 0 | 498 |
output | str(i) | 1 | 498 |
instruction | convert `a` to string | 0 | 499 |
output | a.__str__() | 1 | 499 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.