text
stringlengths 4
1.08k
|
|---|
matplotlib fill beetwen multiple lines,"plt.fill_between(X, Y2, Y3, color='m', alpha=0.5)"
|
get only first element in each of the innermost of the multidimensional list `listd`,[[[x[0]] for x in listD[i]] for i in range(len(listD))]
|
reverse key-value pairs in a dictionary `map`,"dict((v, k) for k, v in map.items())"
|
create a 2d array of `node` objects with dimensions `cols` columns and `rows` rows,nodes = [[Node() for j in range(cols)] for i in range(rows)]
|
read csv file 'myfile.csv' into array,"np.genfromtxt('myfile.csv', delimiter=',')"
|
reverse mapping of dictionary with python,"dict(map(lambda a: [a[1], a[0]], iter(d.items())))"
|
how to write unittest for variable assignment in python?,do_something()
|
how to change the face color of a plot using matplotlib,"ax.plot(x, y, color='g')"
|
generate a random string of length `x` containing lower cased ascii letters,""""""""""""".join(random.choice(string.lowercase) for x in range(X))"
|
regular expression matching all but a string,"re.findall('-(?!aa-|bb-)([^-]+)', string)"
|
can i have a non-greedy regex with dotall?,"re.findall('a*?bc*?', 'aabcc', re.DOTALL)"
|
print list `t` into a table-like shape,"print('\n'.join(' '.join(map(str, row)) for row in t))"
|
duplicating some rows and changing some values in pandas,"pd.concat([good, new], axis=0, ignore_index=True)"
|
how does this function to remove duplicate characters from a string in python work?,print(' '.join(set(s)))
|
loading temporary dlls into python on win32,os.path.exists('./lib.dll')
|
bits list to integer in python,"int(''.join(str(i) for i in my_list), 2)"
|
creating a browse button with tkinter,root.mainloop()
|
how to use numpy's hstack?,"a[:, ([3, 4])]"
|
how to extract the n-th elements from a list of tuples in python?,"map(itemgetter(1), elements)"
|
how can i draw half circle in opencv?,"cv2.imwrite('half_circle_no_round.jpg', image)"
|
filter dict to contain only certain keys?,"foodict = {k: v for k, v in list(mydict.items()) if k.startswith('foo')}"
|
how do i run selenium in xvfb?,browser.quit()
|
can i export a python pandas dataframe to ms sql?,"wildcards = ','.join(['%s'] * len(frame.columns))"
|
how to keep index when using pandas merge,"a.reset_index().merge(b, how='left').set_index('index')"
|
django redirect to root from a view,"url('^$', 'Home.views.index'),"
|
how to convert 'binary string' to normal string in python3?,"""""""a string"""""".decode('ascii')"
|
delete every nth row or column in a matrix using python,"np.delete(a, list(range(0, a.shape[1], 8)), axis=1)"
|
what is the simplest way to create a shaped window in wxpython?,"self.Bind(wx.EVT_PAINT, self.OnPaint)"
|
print a big integer with punctions with python3 string formatting mini-language,"""""""{:,}"""""".format(x)"
|
convert list `myintegers` into a unicode string,""""""""""""".join(chr(i) for i in myintegers)"
|
get the indexes of the x and y axes in numpy array `np` where variable `a` is equal to variable `value`,"i, j = np.where(a == value)"
|
how to use python numpy.savetxt to write strings and float number to an ascii file?,"num.savetxt('test.txt', DAT, delimiter=' ', fmt='%s')"
|
python regex: get end digits from a string,"next(re.finditer('\\d+$', s)).group(0)"
|
convert a hex string `x` to string,"y = str(int(x, 16))"
|
how to convert a list into a pandas dataframe,df[col] = df[col].apply(lambda i: ''.join(i))
|
gradient calculation with python,np.cos(-1.5)
|
how to replace all non-numeric entries with nan in a pandas dataframe?,df[df.applymap(isnumber)]
|
convert dataframe column type from string to datetime,df['col'] = pd.to_datetime(df['col'])
|
multiple positional arguments with python and argparse,"parser.parse_args(['-a', '-b', 'fileone', 'filetwo', 'filethree'])"
|
how can i check if a string contains any letters from the alphabet?,"re.search('[a-zA-Z]', the_string)"
|
python: is it possible to attach a console into a running process,code.interact()
|
get norm of numpy sparse matrix rows,"n = np.sqrt(np.einsum('ij,ij->i', a, a))"
|
convert nested list 'cards' into a flat list,[a for c in Cards for b in c for a in b]
|
python: converting from iso-8859-1/latin1 to utf-8,u8.decode('utf-8') == v.decode('latin1') == u16.decode('utf-16')
|
missing data in pandas.crosstab,"pd.crosstab(a, [b, c], rownames=['a'], colnames=['b', 'c'], dropna=False)"
|
how do i modify a text file in python?,f.write('new line\n')
|
rename `last` row index label in dataframe `df` to `a`,df = df.rename(index={last: 'a'})
|
how to save xlsxwriter file in certain path?,workbook = xlsxwriter.Workbook('C:/Users/Steven/Documents/demo.xlsx')
|
"trim string "" hello """,' Hello '.strip()
|
how to set global const variables in python,GRAVITY = 9.8
|
create a list where each element is a dictionary with keys 'key1' and 'key2' and values corresponding to each value in the lists referenced by keys 'key1' and 'key2' in dictionary `d`,"[{'key1': a, 'key2': b} for a, b in zip(d['key1'], d['key2'])]"
|
convert datetime object to a string of date only in python,"'%s/%s/%s' % (dt.month, dt.day, dt.year)"
|
fabric sudo no password solution,env.password = 'yourpassword'
|
how to remove leading and trailing zeros in a string? python,your_string.strip('0')
|
how to properly use python's isinstance() to check if a variable is a number?,"isinstance(var, (int, float, complex))"
|
python pandas: drop a df column if condition,"dummy_df.loc[:, (~(dummy_df == '0%').all())]"
|
how do i extract all the values of a specific key from a list of dictionaries?,results = [item['value'] for item in test_data]
|
sum a list of numbers in python,sum(i for i in a)
|
how to change the dtype of a numpy recarray?,print(r.dtype)
|
"find all the rows in dataframe 'df2' that are also present in dataframe 'df1', for the columns 'a', 'b', 'c' and 'd'.","pd.merge(df1, df2, on=['A', 'B', 'C', 'D'], how='inner')"
|
sorting while preserving order in python,"sorted(enumerate(a), key=lambda x: x[1])"
|
"run the code contained in string ""print('hello')""","eval(""print('Hello')"")"
|
how do i return a json array with bottle?,"{'data': [{'id': 1, 'name': 'Test Item 1'}, {'id': 2, 'name': 'Test Item 2'}]}"
|
bool value of a list in python,return len(my_list)
|
easiest way to remove unicode representations from a string in python 3?,print(t.decode('unicode_escape'))
|
sort dates in python array,"sorted(timestamps, key=lambda d: map(int, d.split('-')))"
|
set time zone `europe/istanbul` in django,TIME_ZONE = 'Europe/Istanbul'
|
remove empty string from list,mylist = [i for i in mylist if i != '']
|
get the date object `date_of_manufacture` of object `car` in string format '%y-%m-%d',{{car.date_of_manufacture.strftime('%Y-%m-%d')}}
|
how do i fix a valueerror: read of closed file exception?,fo.write(fp.read())
|
how do i autosize text in matplotlib python?,plt.tight_layout()
|
plotting a 2d heatmap with matplotlib,plt.show()
|
efficient loop over numpy array,"np.nonzero(np.any(a, axis=0))[0]"
|
how to find all terms in an expression in sympy,"sympify('1/(x+1)+4*x/(x-1)+3-4*x**2+10*x**2', evaluate=False).args"
|
strip non alpha numeric characters from string in python but keeping special characters,"re.sub('_', '', re.sub(pattern, '', x))"
|
sum the products of each two elements at the same index of list `a` and list `b`,"list(x * y for x, y in list(zip(a, b)))"
|
list of arguments with argparse,"parser.add_argument('-t', dest='table', help='', nargs='+')"
|
string formatting in python version earlier than 2.6,"'%(foo)s %(bar)d' % {'bar': 42, 'foo': 'spam', 'baz': None}"
|
delete items from list of list: pythonic way,my_list = [[x for x in sublist if x not in to_del] for sublist in my_list]
|
reading in integer from stdin in python,n = int(input())
|
replace all non-alphanumeric characters in a string,"re.sub('[^0-9a-zA-Z]+', '*', 'h^&ell`.,|o w]{+orld')"
|
python timedelta issue with negative values,"datetime.timedelta(-1, 86100).total_seconds()"
|
python: can a function return an array and a variable?,result = my_function()
|
convert a pandas dataframe to a dictionary,"{'p': [1, 3, 2], 'q': [4, 3, 2], 'r': [4, 0, 9]}"
|
how to rearrange pandas column sequence?,cols = list(df.columns.values)
|
how can i match the start and end in python's regex?,"re.match('(ftp|http)://.*\\.(jpg|png)$', s)"
|
split filenames with python,os.path.splitext(os.path.basename(f))
|
calcuate mean for selected rows for selected columns in pandas data frame,"df[['a', 'b', 'd']].iloc[[0, 1, 3]].mean(axis=0)"
|
sorting list by an attribute that can be none,my_list.sort(key=nonesorter)
|
how to add an html class to a django form's help_text?,field = models.TextField(help_text=mark_safe('some<br>html'))
|
python sum the values of lists of list,result = [sum(b) for b in a]
|
how to use post method in tornado?,"data = self.get_argument('data', 'No data received')"
|
how to replace back slash character with empty string in python,"result = string.replace('\\', '')"
|
function changes list values and not variable values in python,return [(x + 1) for x in y]
|
most efficient way to implement numpy.in1d for muliple arrays,"[np.nonzero(np.in1d(x, c))[0] for x in [a, b, d, c]]"
|
matplotlib problems plotting logged data and setting its x/y bounds,plt.axis('tight')
|
os.getcwd() for a different drive in windows,os.chdir('l:\\letter')
|
filtering elements from list of lists in python?,"[(x, y, z) for x, y, z in a if (x + y) ** z > 30]"
|
find the index of sub string 'g' in string `str`,str.find('g')
|
python: how do i display a timer in a terminal,time.sleep(1)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.