text
stringlengths 4
1.08k
|
|---|
"append array of strings `['x', 'x', 'x']` into one string",""""""""""""".join(['x', 'x', 'x'])"
|
how to print like printf in python3?,"print('a=%d,b=%d' % (f(x, n), g(x, n)))"
|
using colormaps to set color of line in matplotlib,plt.show()
|
deleting rows in numpy array,"x = numpy.delete(x, 2, axis=1)"
|
get the index value in list `p_list` using enumerate in list comprehension,"{p.id: {'id': p.id, 'position': ind} for ind, p in enumerate(p_list)}"
|
read excel file `file_name` using pandas,"dfs = pd.read_excel(file_name, sheetname=None)"
|
how to rearrange pandas column sequence?,"['a', 'b', 'x', 'y']"
|
google app engine (python) - uploading a file (image),imagedata.image = str(self.request.get('image'))
|
how to decode a unicode-like string in python 3?,"codecs.decode('\\u000D', 'unicode-escape')"
|
how can i convert literal escape sequences in a string to the corresponding bytes?,"""""""\\xc3\\x85a"""""".encode('utf-8').decode('unicode_escape')"
|
what's the equivalent of '*' for beautifulsoup - find_all?,soup.select('tr.colour.blue')
|
create a list of integers with duplicate values in python,"['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c', 'd', 'd', 'd', 'e', 'e', 'e']"
|
python float to in int conversion,int(float('20.0'))
|
how to check if a variable is empty in python?,return bool(value)
|
"how do you use pandas.dataframe columns as index, columns, and values?","df.pivot(index='a', columns='b', values='c')"
|
cannot insert data into an sqlite3 database using python,db.commit()
|
how can i perform a ping or traceroute using native python?,"webb.traceroute('your-web-page-url', 'file-name.txt')"
|
how do i capture sigint in python?,sys.exit()
|
search strings using regular expression in python,"results = [r for k in keywords for r in re.findall(k, message.lower())]"
|
how to draw a heart with pylab,pylab.savefig('heart.png')
|
checking if a variable belongs to a class in python,'b' in list(Foo.__dict__.values())
|
join pandas data frame `frame_1` and `frame_2` with left join by `county_id` and right join by `countyid`,"pd.merge(frame_1, frame_2, left_on='county_ID', right_on='countyid')"
|
how to check if a value exists in a dictionary (python),'one' in iter(d.values())
|
how to get the value of multiple maximas in an array in python,"[0, 16, 17, 18]"
|
remove list from list in python,new_list.append(fruit)
|
how to filter a numpy array with another array's values,a[f]
|
how do i run python code from sublime text 2?,"{'keys': ['ctrl+shift+c'], 'command': 'exec', 'args': {'kill': true}}"
|
removing letters from a list of both numbers and letters,""""""""""""".join([c for c in strs if c.isdigit()])"
|
get a name of function `my_function` as a string,my_function.__name__
|
tkinter - how to create a combo box with autocompletion ,root.mainloop()
|
how to transform an xml file using xslt in python?,"print(ET.tostring(newdom, pretty_print=True))"
|
"difference between using commas, concatenation, and string formatters in python","print('I am printing {x} and {y}'.format(x=x, y=y))"
|
numpy - efficient conversion from tuple to array?,"np.array(x).reshape(2, 2, 4)[:, :, (0)]"
|
replace the last occurence of an expression '</div>' with '</bad>' in a string `s`,"re.sub('(.*)</div>', '\\1</bad>', s)"
|
change the mode of file 'my_script.sh' to permission number 484,"os.chmod('my_script.sh', 484)"
|
"how can i print a string using .format(), and print literal curly brackets around my replaced string","""""""{{{0}:{1}}}"""""".format('hello', 'bonjour')"
|
split a string around any characters not specified,"re.split('[^\\d\\.]+', s)"
|
how to fetch only specific columns of a table in django?,"Entry.objects.values_list('id', 'headline')"
|
how to do many-to-many django query to find book with 2 given authors?,Book.objects.filter(Q(author__id=1) & Q(author__id=2))
|
fastest way to update a bunch of records in queryset in django,Entry.objects.all().update(value=not F('value'))
|
how to write unix end of line characters in windows using python,"f = open('file.txt', 'wb')"
|
django orm get latest for each group,Score.objects.values('student').annotate(latest_date=Max('date'))
|
python pandas how to select rows with one or more nulls from a dataframe without listing columns explicitly?,df[pd.isnull(df).any(axis=1)]
|
how can i know whether my subprocess is waiting for my input ?(in python3),pobj.stdin.flush()
|
how to set selenium python webdriver default timeout?,driver.get('http://www.google.com/')
|
how can i check the value of a dns txt record for a host?,"""""""google.com. 1700 IN TXT ""v=spf1 include:_netblocks.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all\"""""""""
|
how can i split a string into tokens?,"['x', '+', '13.5', '*', '10', 'x', '-', '4', 'e', '1']"
|
email datetime parsing with python,"print(dt.strftime('%a, %b %d, %Y at %I:%M %p'))"
|
numpy matrix vector multiplication,"np.einsum('ji,i->j', a, b)"
|
create a list containing words that contain vowel letter followed by the same vowel in file 'file.text',"[w for w in open('file.txt') if not re.search('[aeiou]{2}', w)]"
|
is there a python method to re-order a list based on the provided new indices?,L = [L[i] for i in ndx]
|
change nan values in dataframe `df` using preceding values in the frame,"df.fillna(method='ffill', inplace=True)"
|
get two random records from model 'mymodel' in django,MyModel.objects.order_by('?')[:2]
|
regular expression matching all but a string,"re.findall('-(?!aa|bb)([^-]+)', string)"
|
how can i convert a python dictionary to a list of tuples?,"[(v, k) for k, v in list(d.items())]"
|
numpy: how to check if array contains certain numbers?,"numpy.in1d(b, a).all()"
|
"sum of sums of each list, in a list of lists named 'lists'.",sum(sum(x) for x in lists)
|
how to convert a date string to different format,"datetime.datetime.strptime('2013-1-25', '%Y-%m-%d').strftime('%-m/%d/%y')"
|
how to disable the minor ticks of log-plot in matplotlib?,"plt.xscale('log', subsx=[2, 3, 4, 5, 6, 7, 8, 9])"
|
how to call a python function with no parameters in a jinja2 template,template_globals.filters['ctest'] = ctest
|
extracting a url in python,"re.findall('(https?://\\S+)', s)"
|
"how do you use pandas.dataframe columns as index, columns, and values?","df.pivot_table(index='a', columns='b', values='c', fill_value=0)"
|
manipulating binary data in python,print(' '.join([str(ord(a)) for a in data]))
|
read a text file with non-ascii characters in an unknown encoding,"lines = codecs.open('file.txt', 'r', encoding='utf-8').readlines()"
|
python code to create a password encrypted zip file?,zipfile.ZipFile('myarchive.zip').extractall(pwd='P4$$W0rd')
|
set value for particular cell in pandas dataframe,df['x']['C'] = 10
|
subsetting a 2d numpy array,"np.meshgrid([1, 2, 3], [1, 2, 3], indexing='ij')"
|
how to modify elements of iterables with iterators? i.e. how to get write-iterators in python?,"[[1, 2, 5], [3, 4, 5]]"
|
how to generate unique equal hash for equal dictionaries?,hash(pformat(a)) == hash(pformat(b))
|
reverse a string `string`,''.join(reversed(string))
|
defining the midpoint of a colormap in matplotlib,ax.set_xticks([])
|
python regex alternative for join,"re.sub('(?<=.)(?=.)', '-', str)"
|
how to mask numpy structured array on multiple columns?,A[(A['segment'] == 42) & (A['material'] == 5)]
|
pandas series to excel,"s.to_frame(name='column_name').to_excel('xlfile.xlsx', sheet_name='s')"
|
how to add a second x-axis in matplotlib,plt.show()
|
pandas: aggregate based on filter on another column,"df.groupby(['Fruit', 'Month'])['Sales'].sum().unstack('Month', fill_value=0)"
|
sorting list of list in python,[sorted(item) for item in data]
|
how can i start the python console within a program (for easy debugging)?,pdb.set_trace()
|
how do i make django's markdown filter transform a carriage return to <br />?,{{value | markdown | linebreaksbr}}
|
is there a python method to re-order a list based on the provided new indices?,"[L[i] for i in [2, 1, 0]]"
|
error when trying to insert values into mysql table with python,"0, '2012-11-06T16:23:36-05:00', 0, None, 23759918, 'baseline', '0 to 100', null, 105114, 2009524, True, 'charge', 'Charge'"
|
parsing tcl lists in python,re.compile('(?<=}})\\s+(?={{)')
|
"matplotlib subplot title, figure title formatting",plt.show()
|
creating a list of objects in python,simplelist = [SimpleClass(count) for count in range(4)]
|
how can i ensure that my python regular expression outputs a dictionary?,"json.loads('{""hello"" : 4}')"
|
set multi index of an existing data frame in pandas,"df.set_index(['Company', 'date'], inplace=True)"
|
converting datetime.date to utc timestamp in python,"timestamp = (dt - datetime(1970, 1, 1)) / timedelta(seconds=1)"
|
impossible lookbehind with a backreference,"print(re.sub('(.)(?<=\\1)', '(\\g<0>)', test))"
|
scatterplot contours in matplotlib,plt.show()
|
how to print utf-8 to console with python 3.4 (windows 8)?,sys.stdout.buffer.write('\xe2\x99\xa0'.encode('cp437'))
|
python gtk+ canvas,Gtk.main()
|
"remove all values within one list `[2, 3, 7]` from another list `a`","[x for x in a if x not in [2, 3, 7]]"
|
python with matplotlib - reusing drawing functions,plt.show()
|
extracting date from a string in python,"dparser.parse('monkey 10/01/1980 love banana', fuzzy=True, dayfirst=True)"
|
use regular expression '((\\d)(?:[()]*\\2*[()]*)*)' to split string `s`,"[i[0] for i in re.findall('((\\d)(?:[()]*\\2*[()]*)*)', s)]"
|
how can i call a python script from a python script,"p = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr)"
|
calcuate mean for selected rows for selected columns in pandas data frame,"df.iloc[[0, 2, 3], [0, 1, 3]].mean(axis=0)"
|
what's the best way to aggregate the boolean values of a python dictionary?,all(dict.values())
|
send data from blobstore as email attachment in gae,blob_reader = blobstore.BlobReader('my_blobstore_key')
|
how to convert false to 0 and true to 1 in python,x = int(x == 'true')
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.