text stringlengths 4 1.08k |
|---|
remove newline in string 'windows eol\r\n' on the right side,'Windows EOL\r\n'.rstrip('\r\n') |
looping through files in a folder,"folder = os.path.join('C:\\', 'Users', 'Sprinting', 'blue')" |
how to get the values from a numpy array using multiple indices,"print(arr[[1, 4, 5]])" |
how to make curvilinear plots in matplotlib,plt.show() |
bulk zeroing of elements in a scipy.sparse_matrix,A = A - A.multiply(B) |
find and replace 2nd occurrence of word 'cat' by 'bull' in a sentence 's',"re.sub('^((?:(?!cat).)*cat(?:(?!cat).)*)cat', '\\1Bull', s)" |
how convert a jpeg image into json file in google machine learning,{'image_bytes': {'b64': 'dGVzdAo='}} |
how to split up a string using 2 split parameters?,"re.findall('%(\\d+)l\\\\%\\((.*?)\\\\\\)', r)" |
how do i edit and delete data in django?,return HttpResponse('deleted') |
how to apply django/jinja2 template filters 'escape' and 'linebreaks' correctly?,{{my_variable | escape | linebreaks | safe}} |
convert sre_match object to string,print(result.group(0)) |
parse and format the date from the github api in python,date.strftime('%c') |
how to check if all values in the columns of a numpy matrix are the same?,"np.equal.reduce([1, 0, 0, 1])" |
removing entries from a numpy array,"result = array[:, (idx)]" |
how do i use a regular expression to match a name?,"re.match('[a-zA-Z][\\w-]*\\Z', 'A\n')" |
print latex-formula with python,plt.show() |
python map list of strings to integer list,[ord(x) for x in letters] |
disabling autoescape in flask,app.run(debug=True) |
delete items from list of list: pythonic way,[[y for y in x if y not in to_del] for x in my_list] |
get logical xor of `a` and `b`,((a and (not b)) or ((not a) and b)) |
check if a given key 'key1' exists in dictionary `dict`,"if ('key1' in dict): |
pass" |
two dimensional array in python,"arr = [[], []]" |
how to debug celery/django tasks running localy in eclipse,CELERY_ALWAYS_EAGER = True |
sorting a list of tuples `list_of_tuples` by second key,"sorted(list_of_tuples, key=lambda tup: tup[1])" |
control charts in python,plt.show() |
how to store a naive datetime in django 1.4,pytz.timezone('Europe/Helsinki').localize(naive) |
convert list of strings to int,[[int(x) for x in sublist] for sublist in lst] |
"pyplot, main title, subplot",plt.show() |
get geys of dictionary `my_dict` that contain any values from list `lst`,"[key for key, value in list(my_dict.items()) if set(value).intersection(lst)]" |
how to filter a dictionary in python?,"dict((k, 'updated') for k, v in d.items() if v is None)" |
how to compare type of an object in python?,isinstance() |
how to convert datetime.date.today() to utc time?,today = datetime.datetime.utcnow().date() |
how to get a variable name as a string in python?,"dict((name, eval(name)) for name in ['some', 'list', 'of', 'vars'])" |
django: query self referencing objects with no child elements,Category.objects.filter(category__isnull=True) |
plot specific rows of a pandas dataframe,df.iloc[2:6].plot(y='b') |
how to generate all permutations of a list in python,"print(list(itertools.product([1, 2, 3], [4, 5, 6])))" |
shuffling/permutating a dataframe in pandas,df.reindex(np.random.permutation(df.index)) |
turn dataframe into frequency list with two column variables in python,"pd.concat([df1, df2], axis=1, keys=['precedingWord', 'comp'])" |
matplotlib customize the legend to show squares instead of rectangles,plt.show() |
"test if either of strings `a` or `b` are members of the set of strings, `['b', 'a', 'foo', 'bar']`","set(['a', 'b']).issubset(['b', 'a', 'foo', 'bar'])" |
secondary axis with twinx(): how to add to legend?,ax2.legend(loc=0) |
efficiently grab gradients from tensorflow?,sess.run(tf.initialize_all_variables()) |
python selenium click on button '.button.c_button.s_button',driver.find_element_by_css_selector('.button.c_button.s_button').click() |
sorting a list of dictionaries based on the order of values of another list,listTwo.sort(key=lambda x: listOne.index(x['eyecolor'])) |
find closest row of dataframe to given time in pandas,df.iloc[i] |
how to create a pandas dataframe from string,"df = pd.read_csv(TESTDATA, sep=';')" |
how to update a plot in matplotlib?,fig.canvas.draw() |
print a unicode string `text`,print(text.encode('windows-1252')) |
removing pairs of elements from numpy arrays that are nan (or another value) in python,a[~np.isnan(a).any(1)] |
create a list which indicates whether each element in `x` and `y` is identical,[(x[i] == y[i]) for i in range(len(x))] |
render an xml to a view,"return HttpResponse(open('myxmlfile.xml').read(), content_type='text/xml')" |
multiply two series with multiindex in pandas,"data_3levels.unstack('l3').mul(data_2levels, axis=0).stack()" |
pythonic way to convert a list of integers into a string of comma-separated ranges,"print(','.join('-'.join(map(str, (g[0][1], g[-1][1])[:len(g)])) for g in G))" |
python convert long to date,datetime.datetime.fromtimestamp(myNumber).strftime('%Y-%m-%d %H:%M:%S') |
appending the same string to a list of strings in python,[(s + mystring) for s in mylist] |
custom constructors for models in google app engine (python),"rufus = Dog(name='Rufus', breeds=['spaniel', 'terrier', 'labrador'])" |
parsing json python,print(json.dumps(data)) |
how to remove gray border from matplotlib,plt.show() |
slicing a numpy array within a loop,"array([[0, 1, 2], [3, 4, 5], [6, 7, 8]])" |
how to bind ctrl+/ in python tkinter?,root.mainloop() |
convert a unicode string `title` to a 'ascii' string,"unicodedata.normalize('NFKD', title).encode('ascii', 'ignore')" |
how to convert dictionary values to int in python?,"results = sorted(ranks, key=lambda x: int(x['rank'].replace(',', '')))" |
how do i turn a dataframe into a series of lists?,"print(pd.Series(df.values.tolist(), index=df.index))" |
ggplot multiple plots in one object,plt.show() |
easiest way to remove unicode representations from a string in python 3?,"re.sub('(\\\\u[0-9A-Fa-f]+)', unescapematch, t)" |
regex match if not before and after,"re.search('suck', s)" |
how to extract tuple values in pandas dataframe for use of matplotlib?,df.head() |
how to change qpushbutton text and background color,setStyleSheet('QPushButton {background-color: #A3C1DA; color: red;}') |
python subprocess in parallel,p.wait() |
closed lines in matplotlib contour plots,plt.savefig('test.pdf') |
fastest way to split a concatenated string into a tuple and ignore empty strings,tuple(a[:-1].split(';')) |
get list of xml attribute values in python,"['a1', 'a2', 'a3']" |
change a string of integers `x` separated by spaces to a list of int,"x = map(int, x.split())" |
summing only the numbers contained in a list,"sum([x for x in list if isinstance(x, (int, float))])" |
python: write a list of tuples to a file,"open('filename', 'w').write('\n'.join('%s %s' % x for x in mylist))" |
how to remove \n from a list element?,"map(lambda x: x.strip(), l)" |
create a list containing keys of dictionary `d` and sort it alphabetically,"sorted(d, key=d.get)" |
sorting a list of tuples by the addition of second and third element of the tuple,"sorted(a, key=lambda x: (sum(x[1:3]), x[0]), reverse=True)" |
"destruct elements of list `[1, 2, 3]` to variables `a`, `b` and `c`","a, b, c = [1, 2, 3]" |
create a list of integers with duplicate values in python,"[0, 0, 1, 1, 2, 2, 3, 3, 4, 4]" |
masking part of a contourf plot in matplotlib,plt.show() |
how to merge two python dictionaries in a single expression?,c = dict(list(a.items()) + list(b.items())) |
how can i clear the python pdb screen?,os.system('cls') |
"recursive ""all paths"" through a list of lists - python","['ab', 'c', 'de', 'fg', 'h']" |
best way to remove elements from a list,[item for item in my_list if 1 <= item <= 5] |
close a tkinter window?,root.destroy() |
removing key values pairs from a list of dictionaries,"[dict((k, v) for k, v in d.items() if k != 'mykey1') for d in mylist]" |
"replace values `['abc', 'ab']` in a column 'brandname' of pandas dataframe `df` with another value 'a'","df['BrandName'] = df['BrandName'].replace(['ABC', 'AB'], 'A')" |
make a list of lists in which each list `g` are the elements from list `test` which have the same characters up to the first `_` character,"[list(g) for _, g in itertools.groupby(test, lambda x: x.split('_')[0])]" |
windows path in python,"os.path.join(mydir, myfile)" |
"remove adjacent duplicate elements from a list `[1, 2, 2, 3, 2, 2, 4]`","[k for k, g in itertools.groupby([1, 2, 2, 3, 2, 2, 4])]" |
convert keys in dictionary `thedict` into case insensitive,theset = set(k.lower() for k in thedict) |
"python, unittest: is there a way to pass command line options to the app",unittest.main() |
how to efficiently calculate the outer product of two series of matrices in numpy?,"C = np.einsum('kmn,kln->kml', A, B)" |
how to generate strong one time session key for aes in python,random_key = os.urandom(16) |
reading gzipped csv file in python 3,"f = gzip.open(filename, mode='rt')" |
how can i convert from scatter size to data coordinates in matplotlib?,plt.draw() |
parsing html data into python list for manipulation,"['13.46', '20.62', '26.69', '30.17', '32.81']" |
how do i get mouse position relative to the parent widget in tkinter?,root.mainloop() |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.