text
stringlengths 4
1.08k
|
|---|
fastest way to convert bitstring numpy array to integer base 2,"np.array([[int(i[0], 2)] for i in a])"
|
"how to filter the dataframe rows of pandas by ""within""/""in""?",b = df[(df['a'] > 1) & (df['a'] < 5)]
|
how can i apply authenticated proxy exceptions to an opener using urllib2?,urllib.request.install_opener(opener)
|
efficient way to compress a numpy array (python),"my_array.compress([(x in ['this', 'that']) for x in my_array['job']])"
|
"return max value from panda dataframe as a whole, not based on column or rows",df.values.max()
|
convert a string `a` of letters embedded in squared brackets into embedded lists,"[i.split() for i in re.findall('\\[([^\\[\\]]+)\\]', a)]"
|
get particular row as series from pandas dataframe,df[df['location'] == 'c'].iloc[0]
|
stratified sampling in numpy,"np.all(np.unique(A[['idx1', 'idx2']]) == np.unique(B[['idx1', 'idx2']]))"
|
what is the definition of mean in pandas data frame?,print(df['col'][0:i].mean())
|
"generate all possible string permutations of each two elements in list `['hel', 'lo', 'bye']`","print([''.join(a) for a in combinations(['hel', 'lo', 'bye'], 2)])"
|
convert a string `s` containing hex bytes to a hex string,binascii.a2b_hex(s)
|
subsetting a 2d numpy array,"a[[1, 2, 3], [1, 2, 3]]"
|
get current url in selenium webdriver `browser`,print(browser.current_url)
|
get the indexes of the largest `2` values from a list of integers `a`,"sorted(list(range(len(a))), key=lambda i: a[i], reverse=True)[:2]"
|
how to send http/1.0 request via urllib2?,print(urllib.request.urlopen('http://localhost/').read())
|
optional get parameters in django?,"url('^so/(?P<required>\\d+)/', include('myapp.required_urls'))"
|
count number of rows in a many-to-many relationship (sqlalchemy),session.query(Entry).join(Entry.tags).filter(Tag.id == 1).count()
|
find synonyms for multi-word phrases,print(wn.synset('main_course.n.01').lemma_names)
|
"convert each key,value pair in a dictionary `{'my key': 'my value'}` to lowercase","dict((k.lower(), v.lower()) for k, v in {'My Key': 'My Value'}.items())"
|
how do i create a histogram from a hashmap in python?,plt.show()
|
delete every 8th column in a numpy array 'a'.,"np.delete(a, list(range(0, a.shape[1], 8)), axis=1)"
|
remove whitespace in string `sentence` from beginning and end,sentence.strip()
|
rotating a two-dimensional array in python,"[[1, 2, 3], [4, 5, 6], [7, 8, 9]]"
|
create broken symlink with python,"os.symlink('/usr/bin/python', '/tmp/subdir/python')"
|
streaming data with python and flask,"app.run(host='localhost', port=23423)"
|
calculate delta from values in dataframe,"df.pivot(index='client_id', columns='month', values='deltas')"
|
unicode representation to formatted unicode?,chr(128512)
|
how to get a matplotlib axes instance to plot to?,plt.show()
|
matplotlib show multiple images with for loop,plt.show()
|
how do i print the content of a .txt file in python?,"f = open('example.txt', 'r')"
|
merge all columns in dataframe `df` into one column,"df.apply(' '.join, axis=0)"
|
how to handle delete in google app engine (python),self.response.out.write(key)
|
pandas: remove reverse duplicates from dataframe,"data.apply(lambda r: sorted(r), axis=1).drop_duplicates()"
|
flask: how to handle application/octet-stream,app.run()
|
remove white space padding around a saved image `test.png` in matplotlib,"plt.savefig('test.png', bbox_inches='tight')"
|
how to serialize sqlalchemy result to json?,json.dumps([dict(list(row.items())) for row in rs])
|
match regex pattern 'taa(?:[atgc]{3})+?taa' on string `seq`,"re.findall('TAA(?:[ATGC]{3})+?TAA', seq)"
|
how to generate python documentation using sphinx with zero configuration?,"sys.path.insert(0, os.path.abspath('/my/source/lives/here'))"
|
python regex for hyphenated words in `text`,"re.findall('\\w+(?:-\\w+)+', text)"
|
listing files from a directory using glob python,glob.glob('[!hello]*')
|
multiprocessing with qt works in windows but not linux,sys.exit(app.exec_())
|
how to make print statement one line in python?,"print('If a hippo ways 2000 pounds, gives birth to a 100 pound calf and ' + 'then eats a 50 pound meal how much does she weigh?')"
|
delete a group after pandas groupby,df.drop(grouped.get_group(group_name).index)
|
python pandas: how to move one row to the first row of a dataframe?,df.set_index('a')
|
best way to structure a tkinter application,root.mainloop()
|
"python, format string","""""""{0} %s {1}"""""".format('foo', 'bar')"
|
"given list `to_reverse`, reverse the all sublists and the list itself",[sublist[::-1] for sublist in to_reverse[::-1]]
|
arrow on a line plot with matplotlib,plt.show()
|
how do i load session and cookies from selenium browser to requests library in python?,cookies = driver.get_cookies()
|
how can i do multiple substitutions using regex in python?,"re.sub('(.)', '\\1\\1', text.read(), 0, re.S)"
|
find all digits between two characters `\xab` and `\xbb`in a string `text`,"print(re.findall('\\d+', '\n'.join(re.findall('\xab([\\s\\S]*?)\xbb', text))))"
|
how to read stdin to a 2d python array of integers?,"a = [map(int, row.split()) for row in stdin]"
|
plot only on continent in matplotlib,plt.show()
|
datetime to string with series in python pandas,dates.dt.strftime('%Y-%m-%d')
|
showing an image from console in python,img.show()
|
python - how to cut a string in python?,s.rfind('&')
|
how to make a pandas crosstab with percentages?,"pd.crosstab(df.A, df.B).apply(lambda r: r / r.sum(), axis=1)"
|
how to combine two data frames in python pandas,"df_col_merged = pd.concat([df_a, df_b], axis=1)"
|
reading data from a csv file online in python 3,datareader = csv.reader(webpage.read().decode('utf-8').splitlines())
|
export a table dataframe `df` in pyspark to csv 'mycsv.csv',df.toPandas().to_csv('mycsv.csv')
|
time data does not match format,"datetime.strptime('07/28/2014 18:54:55.099', '%m/%d/%Y %H:%M:%S.%f')"
|
python 3: how do i get a string literal representation of a byte string?,"""""""x = {}"""""".format(x.decode('utf8')).encode('utf8')"
|
show terminal output in a gui window using python gtk,gtk.main()
|
how to find values from one dataframe in another using pandas?,"print(pd.merge(df1, df2, on='B')['B'])"
|
sort a sublist of elements in a list leaving the rest in place,"s1 = ['11', '2', 'A', 'B', 'B1', 'B11', 'B2', 'B21', 'C', 'C11', 'C2']"
|
how to use 'user' as foreign key in django 1.5,"user = models.ForeignKey('User', unique=True)"
|
most efficient way to forward-fill nan values in numpy array,"arr[mask] = arr[np.nonzero(mask)[0], idx[mask]]"
|
from nd to 1d arrays,c = a.flatten()
|
customizing just one side of tick marks in matplotlib using spines,"ax.tick_params(axis='y', direction='out')"
|
delete an element with key `key` dictionary `r`,del r[key]
|
convert a list of characters into a string,""""""""""""".join(['a', 'b', 'c', 'd'])"
|
extract dictionary `d` from list `a` where the value associated with the key 'name' of dictionary `d` is equal to 'pluto',[d for d in a if d['name'] == 'pluto']
|
throw a runtime error with message 'specific message',raise RuntimeError('specific message')
|
decimal precision in python without decimal module,print(str(intp) + '.' + str(fracp).zfill(prec))
|
adjusting heights of individual subplots in matplotlib in python,plt.show()
|
multiple statements in list compherensions in python?,"[i for i, x in enumerate(testlist) if x == 1]"
|
python - readable list of objects,print([obj.attr for obj in my_list_of_objs])
|
return a list of weekdays,print(weekdays('Wednesday'))
|
how do i get a list of all the duplicate items using pandas in python?,"pd.concat(g for _, g in df.groupby('ID') if len(g) > 1)"
|
get all texts and tags from a tag `strong` from etree tag `some_tag` using lxml,print(etree.tostring(some_tag.find('strong')))
|
how can i use a string with the same name of an object in python to access the object itself?,"getattr(your_obj, x)"
|
sorting a graph by its edge weight. python,"lst.sort(key=lambda x: x[2], reverse=True)"
|
pythons fastest way of randomising case of a string,""""""""""""".join(x.upper() if random.randint(0, 1) else x for x in s)"
|
compare if each value in list `a` is less than respective index value in list `b`,"all(i < j for i, j in zip(a, b))"
|
fitting data with numpy,"np.polyfit(x, y, 4)"
|
python list of tuples to list of int,y = (i[0] for i in x)
|
how to slice a dataframe having date field as index?,df = df.set_index(['TRX_DATE'])
|
how to smooth matplotlib contour plot?,plt.show()
|
sort a pandas data frame with column `a` in ascending and `b` in descending order,"df1.sort(['a', 'b'], ascending=[True, False], inplace=True)"
|
how to specify column names while reading an excel file using pandas?,"df = xl.parse('Sheet1', header=None)"
|
regex search and split string 'aaa bbb ccc ddd eee fff' by delimiter '(d(d)d)',"re.split('(d(d)d)', 'aaa bbb ccc ddd eee fff', 1)"
|
python and urllib2: how to make a get request with parameters,"urllib.parse.urlencode({'foo': 'bar', 'bla': 'blah'})"
|
"how can i remove all words that end in "":"" from a string in python?",print(' '.join(i for i in word.split(' ') if not i.endswith(':')))
|
passing variables from python to bash shell script via os.system,os.system('echo $probe1')
|
union of dict objects in python,"dict({'a': 'y[a]'}, **{'a', 'x[a]'}) == {'a': 'x[a]'}"
|
how to send an email with gmail as provider using python?,server.starttls()
|
annotate a plot using matplotlib,plt.show()
|
convert svg to png in python,img.write_to_png('svg.png')
|
what is the max length of a python string?,print(str(len(s)) + ' bytes')
|
how to define free-variable in python?,foo()
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.