text
stringlengths 4
1.08k
|
|---|
how do i output info to the console in a gimp python script?,main()
|
add colorbar to existing axis,plt.show()
|
how to convert list of intable strings to int,list_of_lists = [[try_int(x) for x in lst] for lst in list_of_lists]
|
tuple digits to number conversion,"sum(Decimal(n) * Decimal(10) ** Decimal(i) for i, n in zip(count(0, -1), a))"
|
get a list `y` of the first element of every tuple in list `x`,y = [i[0] for i in x]
|
get the last element in list `astr`,astr[(-1)]
|
disable console messages in flask server,app.run()
|
get the creation time of file `file`,print(('created: %s' % time.ctime(os.path.getctime(file))))
|
generate six unique random numbers in the range of 1 to 49.,"random.sample(range(1, 50), 6)"
|
sort list `users` using values associated with key 'id' according to elements in list `order`,users.sort(key=lambda x: order.index(x['id']))
|
can i sort text by its numeric value in python?,"sorted(list(mydict.items()), key=lambda a: map(int, a[0].split('.')))"
|
get index of numpy array `a` with another numpy array `b`,a[tuple(b)]
|
how to printing numpy array with 3 decimal places?,np.set_printoptions(formatter={'float': lambda x: '{0:0.3f}'.format(x)})
|
finding duplicates in a list of lists,"map(list, list(totals.items()))"
|
how do i get a list of all the duplicate items using pandas in python?,"df[df.duplicated(['ID'], keep=False)]"
|
how can i use a string with the same name of an object in python to access the object itself?,locals()[x]
|
pythonic way to print list items,print(''.join([str(x) for x in l]))
|
getting the first elements per row in an array in python?,t = tuple(x[0] for x in s)
|
how to plot blurred points in matplotlib,plt.show()
|
pandas replace all items in a row with nan if one value is nan,"df.loc[(df.isnull().any(axis=1)), :] = np.nan"
|
consuming com events in python,time.sleep(0.1)
|
data structure to represent multiple equivalent keys in set in python?,"[[1, 2], [2], [2, 2, 3], [1, 2, 3]]"
|
get the size of list `items`,len(items)
|
how to convert a date string to different format,"datetime.datetime.strptime('2013-1-25', '%Y-%m-%d').strftime('%m/%d/%y')"
|
how do i use a dictionary to update fields in django models?,Book.objects.create(**d)
|
how to read bits from a file?,sys.stdout.write(chr(x))
|
change directory to the directory of a python script,os.chdir(os.path.dirname(__file__))
|
how to disable query cache with mysql.connector,con.commit()
|
php to python pack('h'),binascii.unhexlify('44756d6d7920537472696e67')
|
convert string date to timestamp in python,"time.mktime(datetime.datetime.strptime(s, '%d/%m/%Y').timetuple())"
|
python: setting an element of a numpy matrix,"a[i, j] = x"
|
setting focus to specific tkinter entry widget,root.mainloop()
|
save a numpy array `image_array` as an image 'outfile.jpg',"scipy.misc.imsave('outfile.jpg', image_array)"
|
how can i iterate and apply a function over a single level of a dataframe with multiindex?,"df.groupby(level=0, axis=1).sub(df['IWWGCW'].values)"
|
django filter jsonfield list of dicts,Test.objects.filter(actions__contains={'fixed_key_1': 'foo2'})
|
how do i edit and delete data in django?,emp.delete()
|
how to convert 'binary string' to normal string in python3?,"""""""a string"""""".encode('ascii')"
|
how to move identical elements in numpy array into subarrays,"np.split(a, np.nonzero(np.diff(a))[0] + 1)"
|
replace all non-alphanumeric characters in a string,"s = re.sub('[^0-9a-zA-Z]+', '*', s)"
|
adding colors to a 3d quiver plot in matplotlib,plt.show()
|
how to convert pointer to c array to python array,a = np.frombuffer(Data)
|
pandas: create new dataframe that averages duplicates from another dataframe,"df.groupby(level=0, axis=1).mean()"
|
how can i list only the folders in zip archive in python?,set([os.path.split(x)[0] for x in zf.namelist() if '/' in x])
|
slicing numpy array with another array,"a = np.concatenate((a, [0]))"
|
create a list with the sum of respective elements of the tuples of list `l`,[sum(x) for x in zip(*l)]
|
apply vs transform on a group object,df.groupby('A')['C'].transform(zscore)
|
pandas create new column based on values from other columns,"df['race_label'] = df.apply(lambda row: label_race(row), axis=1)"
|
how to specify column names while reading an excel file using pandas?,"df.columns = ['W', 'X', 'Y', 'Z']"
|
trying to use raw input with functions,s = input('--> ')
|
how can i do a batch insert into an oracle database using python?,connection.close()
|
get the row names from index in a pandas data frame,df.index
|
how can i make a for-loop pyramid more concise in python?,"list(product(list(range(3)), repeat=4))"
|
matplotlib legend markers only once,legend(numpoints=1)
|
how would i check a string for a certain letter in python?,"'x' in ['x', 'd', 'a', 's', 'd', 's']"
|
using a python dict for a sql insert statement,"cursor.execute(sql, list(myDict.values()))"
|
how in python to split a string with unknown number of spaces as separator?,""""""" 1234 Q-24 2010-11-29 563 abc a6G47er15"""""".split()"
|
get the ascii value of a character as an int,ord()
|
python: get key of index in dictionary,"[k for k, v in i.items() if v == 0]"
|
python tkinter how to bind key to a button,"master.bind('s', self.sharpen)"
|
print variable `count` and variable `conv` with space string ' ' in between,print(str(count) + ' ' + str(conv))
|
how do i use extended characters in python's curses library?,window.addstr('\xcf\x80')
|
how to remove rows with null values from kth column onward in python,"df2.dropna(subset=['three', 'four', 'five'], how='all')"
|
how to read a file byte by byte in python and how to print a bytelist as a binary?,file.read(1)
|
get index of the top n values of a list in python,"zip(*sorted(enumerate(a), key=operator.itemgetter(1)))[0][-2:]"
|
convert string date to timestamp in python,"int(datetime.datetime.strptime('01/12/2011', '%d/%m/%Y').strftime('%s'))"
|
sorting a list of dictionary values by date in python,"rows.sort(key=itemgetter(1), reverse=True)"
|
using resample to align multiple timeseries in pandas,"print(df.resample('Q-APR', loffset='-1m').T)"
|
animating pngs in matplotlib using artistanimation,plt.show()
|
pandas: best way to select all columns starting with x,df.loc[(df == 1).any(axis=1)]
|
calling a function named 'myfunction' in the module,globals()['myfunction']()
|
how to get the list of options that python was compiled with?,sysconfig.get_config_var('HAVE_LIBREADLINE')
|
sorting a dictionary by value then by key,"sorted(list(y.items()), key=lambda x: (x[1], x[0]), reverse=True)"
|
python: using a dict to speed sorting of a list of tuples,list_dict = {t[0]: t for t in tuple_list}
|
how do i match zero or more brackets in python regex,"re.sub('\\[.*\\]|\\{.*\\}', '', one)"
|
how to do this group by query in django's orm with annotate and aggregate,Article.objects.values('pub_date').annotate(article_count=Count('title'))
|
reading a csv into pandas where one column is a json string,df.join(df['stats'].apply(json.loads).apply(pd.Series))
|
how to input 2 integers in one line in python?,"a, b = map(int, input().split())"
|
referring to the first element of all tuples in a list of tuples,[x[0] for x in tuple_list]
|
understanding list comprehension for flattening list of lists in python,[item for sublist in list_of_lists for item in sublist]
|
"download ""http://randomsite.com/file.gz"" from http and save as ""file.gz""","testfile = urllib.request.URLopener()
|
testfile.retrieve('http://randomsite.com/file.gz', 'file.gz')"
|
python: how to generate a 12-digit random number?,"random.randint(100000000000, 999999999999)"
|
read lines containing integers from a file in python?,"line = ['3', '4', '1\r\n']"
|
how to get a matplotlib axes instance to plot to?,ax = plt.gca()
|
creating a dictionary from an iterable,"{i: (0) for i in range(0, 10)}"
|
convert dict `result` to numpy structured array,"numpy.array([(key, val) for key, val in result.items()], dtype)"
|
update a list `l1` dictionaries with a key `count` and value from list `l2`,"[dict(d, count=n) for d, n in zip(l1, l2)]"
|
python regular expression match all 5 digit numbers but none larger,"re.findall('\\D(\\d{5})\\D', ' ' + s + ' ')"
|
extract item from list of dictionaries,[d for d in a if d['name'] == 'pluto']
|
"check whether a file ""/does/not/exist"" exists",print(os.path.isfile('/does/not/exist'))
|
set the resolution of a monitor as `fullscreen` in pygame,"pygame.display.set_mode((0, 0), pygame.FULLSCREEN)"
|
how to get the index of dictionary with the highest value in a list of dictionary,"max(lst, key=lambda d: d['score'])"
|
get a list from two strings `12345` and `ab` with values as each character concatenated,[(x + y) for x in '12345' for y in 'ab']
|
merge 2 dataframes `df1` and `df2` with same values in a column 'revenue' with and index 'date',df2['revenue'] = df2.CET.map(df1.set_index('date')['revenue'])
|
how to adjust the size of matplotlib legend box?,ax.legend(loc='upper left')
|
how to filter files (with known type) from os.walk?,"files = [file for file in files if not file.endswith(('.dat', '.tar'))]"
|
how to find common elements in list of lists?,set([1])
|
python precision in string formatting with float numbers,"format(38.2551994324, '.32f')"
|
sort a sublist of elements in a list leaving the rest in place,"['X', 'B', 'B1', 'B2', 'B11', 'B21', 'C', 'Q1', 'C11', 'C2', 'B22']"
|
formatting text to be justified in python 3.3 with .format() method,"""""""{:20s}"""""".format(mystring)"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.