text
stringlengths 4
1.08k
|
|---|
layout images in form of a number,"img.save('/tmp/out.png', 'PNG')"
|
how to construct a dictionary from two dictionaries in python?,"{'y2': 2, 'y1': 1, 'x2': 2, 'x3': 3, 'y3': 3, 'x1': 1}"
|
selenium open pop up window [python],"driver.find_element_by_css_selector(""a[href^='javascript']"").click()"
|
how do i print out just the word itself in a wordnet synset using python nltk?,[synset.name.split('.')[0] for synset in wn.synsets('dog')]
|
slice pandas dataframe where column's value exists in another array,df.query('a in @keys')
|
python: get relative path from comparing two absolute paths,"print(os.path.relpath('/usr/var/log/', '/usr/var'))"
|
remove all elements of a set that contain a specific char,[x for x in primes if '0' not in str(x)]
|
convert a set of tuples `queryresult` to a list of strings,[item[0] for item in queryresult]
|
scope of eval function in python,"dict((name, eval(name, globals(), {})) for name in ['i', 'j', 'k'])"
|
get a random string of length `length`,return ''.join(random.choice(string.lowercase) for i in range(length))
|
python: how to order a list based on another list,"sorted(list1, key=lambda x: wordorder.get(x.split('-')[1], len(wordorder)))"
|
getting file size in python?,os.stat('C:\\Python27\\Lib\\genericpath.py').st_size
|
python - regex search and findall,"regex = re.compile('\\d+(?:,\\d+)*')"
|
sorting a heterogeneous list of objects in python,"sorted(itemized_action_list, key=attrgetter('priority'))"
|
python pandas: drop rows of a timeserie based on time range,df.query('index < @start_remove or index > @end_remove')
|
assigning a value to an element of a slice in python,a[0:1][0][0] = 5
|
python save to file,file.write('whatever')
|
set very low values to zero in numpy,"np.isclose([10000000000.0, 1e-07], [10000100000.0, 1e-08])"
|
how to properly split this list of strings?,"[['z', '+', '2', '-', '44'], ['4', '+', '55', '+', 'z', '+', '88']]"
|
how can i get href links from html using python?,"soup.findAll('a', attrs={'href': re.compile('^http://')})"
|
how to unquote a urlencoded unicode string in python?,urllib.parse.unquote(url).decode('utf8')
|
delete digits in python (regex),"re.sub('\\b\\d+\\b', '', s)"
|
how to flush the printed statements in ipython,sys.stdout.flush()
|
how to add an xml node based on the value of a text node,print(lxml.etree.tostring(tree))
|
fill multiple missing values with series based on index values,"s = pd.Series([10, 20, 30], ['x', 'y', 'z'])"
|
how to get utc time in python?,"return (now - datetime.datetime(1970, 1, 1)).total_seconds()"
|
non-destructive version of pop() for a dictionary,"k, v = next(iter(list(d.items())))"
|
decode utf-8 code `x` into a raw unicode literal,print(str(x).decode('raw_unicode_escape'))
|
add a vertical slider with matplotlib,ax.set_yticks([])
|
make a flat list from list of lists `list2d`,list(itertools.chain.from_iterable(list2d))
|
how to teach beginners reversing a string in python?,s[::-1]
|
return pandas dataframe from postgresql query with sqlalchemy,"df = pd.read_sql_query('select * from ""Stat_Table""', con=engine)"
|
how to encode integer in to base64 string in python 3,"""""""1"""""".encode()"
|
python regex returns a part of the match when used with re.findall,"""""""\\$\\d+(?:\\.\\d{2})?"""""""
|
get current url in python,self.request.get('name-of-querystring-variable')
|
how can i determine the length of a multi-page tiff using python image library (pil)?,img.seek(1)
|
slicing a multidimensional list,[[x[0] for x in listD[3]]]
|
how to create broken vertical bar graphs in matpltolib?,plt.show()
|
how can i get list of only folders in amazon s3 using python boto,"list(bucket.list('', '/'))"
|
matplotlib cursor value with two axes,plt.show()
|
format ints into string of hex,""""""""""""".join('%02x' % i for i in input)"
|
how to convert a nested list into a one-dimensional list in python?,"list(flatten([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))"
|
get value of the environment variable 'home' with default value '/home/username/',"print(os.environ.get('HOME', '/home/username/'))"
|
how to initialize multiple columns to existing pandas dataframe,df.reindex(columns=list['cd'])
|
remove all items from a dictionary `mydict` whose values are `42`,"{key: val for key, val in list(myDict.items()) if val != 42}"
|
sum all values of a counter in python,"sum(Counter({'a': 2, 'b': 2, 'c': 2, 'd': 1}).values())"
|
how to filter a numpy.ndarray by date?,"A[:, (0)] > datetime.datetime(2002, 3, 17, 0, 0, 0)"
|
how to make two markers share the same label in the legend using matplotlib?,ax.set_xlabel('Distance from heated face($10^{-2}$ m)')
|
how to filter by sub-level index in pandas,df.index
|
how to replace unicode characters in string with something else python?,"str.decode('utf-8').replace('\u2022', '*').encode('utf-8')"
|
how to implement a watchdog timer in python?,time.sleep(0.1)
|
python - how to sort a list of numerical values in ascending order,"sorted(['10', '3', '2'])"
|
get items from list `a` that don't appear in list `b`,[y for y in a if y not in b]
|
check if file `filename` is descendant of directory '/the/dir/',"os.path.commonprefix(['/the/dir/', os.path.realpath(filename)]) == '/the/dir/'"
|
convert a string into a list,list('hello')
|
django rest framework - serializing optional fields,"super(ProductSerializer, self).__init__(*args, **kwargs)"
|
python extract data from file,words = line.split()
|
plot specific rows of a pandas dataframe,data.iloc[499:999].plot(y='value')
|
how to change the window title in pyside?,self.setWindowTitle('QtGui.QCheckBox')
|
sorting a defaultdict by value in python,"sorted(iter(cityPopulation.items()), key=lambda k_v: k_v[1][2], reverse=True)"
|
matplotlib chart - creating horizontal bar chart,ax.set_xlabel('Performance')
|
case insensitive string comparison between `string1` and `string2`,"if (string1.lower() == string2.lower()):
|
pass"
|
regular expression in python sentence extractor,"re.split('\\.\\s', re.sub('\\.\\s*$', '', text))"
|
multiplying in a list python,"sum(a * b for a, b in zip(it, it))"
|
get data from dataframe `df` where column 'x' is equal to 0,df.groupby('User')['X'].transform(sum) == 0
|
convert decimal 8 to a list of its binary values,list('{0:0b}'.format(8))
|
python - how to sort a list of numerical values in ascending order,"sorted(['10', '3', '2'], key=int)"
|
python: avoid new line with print command,"print(('Nope, that is not a two. That is a', x))"
|
python/matplotlib - colorbar range and display values,plt.show()
|
how to get month name of datetime `today`,today.strftime('%B')
|
how to add a specific number of characters to the end of string in pandas?,"s = pd.Series(['A', 'B', 'A1R', 'B2', 'AABB4'])"
|
dot notation string manipulation,""""""""""""".join('[{}]'.format(e) for e in s.split('.'))"
|
pythonically add header to a csv file,"writer.writerow(['Date', 'temperature 1', 'Temperature 2'])"
|
how to custom sort an alphanumeric list?,"sorted(l, key=lambda x: x.replace('0', 'Z'))"
|
creating sets of tuples in python,"mySet = set(itertools.product(list(range(1, 51)), repeat=2))"
|
remove duplicate characters from string 'ffffffbbbbbbbqqq',"re.sub('([a-z])\\1+', '\\1', 'ffffffbbbbbbbqqq')"
|
python/matplotlib - is there a way to make a discontinuous axis?,"ax2.plot(x, y, 'bo')"
|
how to do multiple arguments to map function where one remains the same in python?,"map(lambda x: x + 2, [1, 2, 3])"
|
"dictionary `d` to string, custom format","""""""<br/>"""""".join([('%s:: %s' % (key, value)) for key, value in list(d.items())])"
|
python mysql parameterized queries,"c.execute('SELECT * FROM foo WHERE bar = %s AND baz = %s', (param1, param2))"
|
python copy a list of lists,new_list = [x[:] for x in old_list]
|
how do you call a python file that requires a command line argument from within another python file?,"call(['path/to/python', 'test2.py', 'neededArgumetGoHere'])"
|
how do i print a celsius symbol with matplotlib?,ax.set_xlabel('Temperature (\u2103)')
|
how to create a group id based on 5 minutes interval in pandas timeseries?,df.groupby(pd.TimeGrouper('5Min'))['val'].mean()
|
changing the color of the offset in scientific notation in matplotlib,plt.show()
|
regex add character to matched string,"re.sub('\\.(?=[^ .])', '. ', para)"
|
how do i find the distance between two points?,"dist = math.hypot(x2 - x1, y2 - y1)"
|
scale an image in gtk,image = gtk.image_new_from_pixbuf(pixbuf)
|
make the if else statement one liner in python,"uly = uly.replace('-', 'S') if '-' in uly else 'N' + uly"
|
how to get the values from a numpy array using multiple indices,"arr[[0, 1, 1], [1, 0, 2]]"
|
python: convert numerical data in pandas dataframe to floats in the presence of strings,df.convert_objects(convert_numeric=True)
|
convert json to csv,csv_file.close()
|
how to convert a numpy 2d array with object dtype to a regular 2d array of floats,"np.array(arr[:, (1)])"
|
remove duplicates elements from list `sequences` and sort it in ascending order,sorted(set(itertools.chain.from_iterable(sequences)))
|
what would be the python code to add time to a specific timestamp?,"datetime.strptime('21/11/06 16:30', '%d/%m/%y %H:%M')"
|
sorting list of lists by a third list of specified non-sorted order,"sorted(a, key=lambda x: b.index(x[0]))"
|
"django get the value of key 'title' from post request `request` if exists, else return empty string ''","request.POST.get('title', '')"
|
how do i get current url in selenium webdriver 2 python?,print(browser.current_url)
|
convert float to comma-separated string,"""""""{0:,.2f}"""""".format(24322.34)"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.