text stringlengths 4 1.08k |
|---|
Non-consuming regular expression split in Python,"re.split('(?<=[\\.\\?!]) ', text)" |
Pandas groupby: How to get a union of strings,df.groupby('A')['C'].apply(lambda x: x.sum()) |
How to calculate quantiles in a pandas multiindex DataFrame?,"df.groupby(level=[0, 1]).median()" |
Pandas - FillNa with another column,df['Cat1'].fillna(df['Cat2']) |
Print multiple arguments in python,"print(('Total score for', name, 'is', score))" |
How to create a Manhattan plot with matplotlib in python?,plt.show() |
Python - How to extract the last x elements from a list,my_list[-10:] |
How do I read the first line of a string?,"my_string.split('\n', 1)[0]" |
Remove adjacent duplicate elements from a list,"[k for k, g in itertools.groupby([1, 2, 2, 3, 2, 2, 4])]" |
Python: How can I execute a jar file through a python script,"subprocess.call(['java', '-jar', 'Blender.jar'])" |
Adding calculated column(s) to a dataframe in pandas,"d.apply(lambda row: min([row['A'], row['B']]) - row['C'], axis=1)" |
How to use the mv command in Python with subprocess,"subprocess.call('mv /home/somedir/subdir/* somedir/', shell=True)" |
Python check if all elements of a list are the same type,"all(isinstance(x, int) for x in lst)" |
What is the best way to create a string array in python?,strs = ['' for x in range(size)] |
How to copy files to network path or drive using Python,os.system('NET USE P: /DELETE') |
How can i parse a comma delimited string into a list (caveat)?,"['foo', 'bar', 'one, two', 'three four']" |
How to click on the text button using selenium python,browser.find_element_by_class_name('section-select-all').click() |
NumPy List Comprehension Syntax,"[[X[i, j] for i in range(X.shape[0])] for j in range(x.shape[1])]" |
How to change folder names in python?,"os.rename('Joe Blow', 'Blow, Joe')" |
How can I check if a checkbox is checked in Selenium Python Webdriver?,driver.find_element_by_id('<check_box_id>').is_selected() |
Dumping subprcess output in a file in append mode,fh1.seek(2) |
How do I extract all the values of a specific key from a list of dictionaries?,results = [item['value'] for item in test_data] |
How to select element with Selenium Python xpath,"driver.find_element_by_xpath(""//div[@id='a']//a[@class='click']"")" |
"Regex to match 'lol' to 'lolllll' and 'omg' to 'omggg', etc","re.sub('l+', 'l', 'lollll')" |
How to handle a HTTP GET request to a file in Tornado?,"('/static/(.*)', web.StaticFileHandler, {'path': '/var/www'})," |
Pandas : Delete rows based on other rows,"pd.merge(df.reset_index(), df, on='sseqid')" |
extract item from list of dictionaries,[d for d in a if d['name'] == 'pluto'] |
Hexagonal Self-Organizing map in Python,"(i + 1, j), (i - 1, j), (i, j - 1), (i, j + 1), (i + 1, j - 1), (i + 1, j + 1)" |
How do I remove dicts from a list with duplicate fields in python?,"list(dict((x['id'], x) for x in L).values())" |
String formatting in Python,"print('[{0}, {1}, {2}]'.format(1, 2, 3))" |
NumPy List Comprehension Syntax,"[[X[i, j] for j in range(X.shape[1])] for i in range(x.shape[0])]" |
Add string in a certain position in Python,s[:4] + '-' + s[4:] |
Removing duplicate characters from a string,""""""""""""".join(set(foo))" |
Pandas groupby: How to get a union of strings,df.groupby('A').apply(lambda x: x.sum()) |
How to write a confusion matrix in Python?,"array([[3, 0, 0], [0, 1, 2], [2, 1, 3]])" |
How to get everything after last slash in a URL?,"url.rsplit('/', 1)[-1]" |
how to clear the screen in python,os.system('clear') |
converting a list of integers into range in python,"[(0, 4), (7, 9), (11, 11)]" |
Python convert decimal to hex,hex(dec).split('x')[1] |
"Python server ""Only one usage of each socket address is normally permitted""","s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)" |
Find all occurrences of a substring in Python,"[m.start() for m in re.finditer('test', 'test test test test')]" |
Plot logarithmic axes with matplotlib in python,ax.set_yscale('log') |
Sorting list based on values from another list?,"[x for y, x in sorted(zip(Y, X))]" |
How to modify a variable inside a lambda function?,"myFunc(lambda a, b: iadd(a, b))" |
Python regular expression matching a multiline block of text,"re.compile('^(.+)(?:\\n|\\r\\n?)((?:(?:\\n|\\r\\n?).+)+)', re.MULTILINE)" |
Sort dictionary of dictionaries by value,"sorted(list(statuses.items()), key=lambda x: getitem(x[1], 'position'))" |
Reverse Y-Axis in PyPlot,plt.gca().invert_yaxis() |
pandas pivot table of sales,"df.groupby(['saleid', 'upc']).size().unstack(fill_value=0)" |
How to turn a boolean array into index array in numpy,numpy.where(mask) |
Pandas groupby: How to get a union of strings,"df.groupby('A')['C'].apply(lambda x: '{%s}' % ', '.join(x))" |
"How do I iterate over a Python dictionary, ordered by values?","sorted(list(dictionary.items()), key=lambda x: x[1])" |
Google App Engine - Request class query_string,self.request.get('var_name') |
What's the Pythonic way to combine two sequences into a dictionary?,"dict(zip(keys, values))" |
Numpy: How to check if array contains certain numbers?,numpy.array([(x in a) for x in b]) |
"python, subprocess: reading output from subprocess",p.stdin.flush() |
How can I list the contents of a directory in Python?,glob.glob('/home/username/www/*') |
How can I write a list of lists into a txt file?,"[[0, 1, 2, 3, 4], ['A', 'B', 'C', 'D', 'E'], [0, 1, 2, 3, 4]]" |
python split string based on regular expression,"re.split('\\s+', str1)" |
Python BeautifulSoup Extract specific URLs,"soup.find_all('a', href=re.compile('^(?!(?:[a-zA-Z][a-zA-Z0-9+.-]*:|//))'))" |
How to create ternary contour plot in Python?,plt.axis('off') |
Map two lists into a dictionary in Python,"dict([(k, v) for k, v in zip(keys, values)])" |
TypeError: expected string or buffer in Google App Engine's Python,self.response.out.write(str(parsed_data['translatedText'])) |
How do I autosize text in matplotlib python?,plt.show() |
List of all unique characters in a string?,list(set('aaabcabccd')) |
Multiplication of 1d arrays in numpy,"np.outer(a, b)" |
Python: Getting rid of \u200b from a string using regular expressions,"'used\u200b'.replace('\u200b', '*')" |
How to find row of 2d array in 3d numpy array,"np.argwhere(np.all(arr == [[0, 3], [3, 0]], axis=(1, 2)))" |
Best way to get the nth element of each tuple from a list of tuples in Python,[x[0] for x in G] |
Flask application traceback doesn't show up in server log,app.run(debug=True) |
How to apply standardization to SVMs in scikit-learn?,X_train = scaler.fit(X_train).transform(X_train) |
How to extract a floating number from a string,"re.findall('[-+]?\\d*\\.\\d+|\\d+', 'Current Level: -13.2 db or 14.2 or 3')" |
"In Python 2.5, how do I kill a subprocess?","os.kill(process.pid, signal.SIGKILL)" |
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')) |
splitting unicode string into words,'\u0440\u0430\u0437 \u0434\u0432\u0430 \u0442\u0440\u0438'.split() |
Map two lists into a dictionary in Python,"dict((k, v) for k, v in zip(keys, values))" |
How to use regex with optional characters in python?,"print(re.match('(\\d+(\\.\\d+)?)', '3434').group(1))" |
What's the usage to add a comma after self argument in a class method?,"{'top': ['foo', 'bar', 'baz'], 'bottom': ['qux']}" |
How to add a specific number of characters to the end of string in Pandas?,"s = pd.Series(['A', 'B', 'A1R', 'B2', 'AABB4'])" |
removing duplicates of a list of sets,[set(item) for item in set(frozenset(item) for item in L)] |
Pandas Groupby Range of Values,"df.groupby(pd.cut(df['B'], np.arange(0, 1.0 + 0.155, 0.155))).sum()" |
Array indexing in numpy,"x[(np.arange(x.shape[0]) != 1), :, :]" |
How to search for a word and then replace text after it using regular expressions in python?,"re.sub('(<form.*?action="")([^""]+)', '\\1newlogin.php', content)" |
How to generate all permutations of a list in Python,"itertools.permutations([1, 2, 3])" |
How to replace unicode characters in string with something else python?,"str.decode('utf-8').replace('\u2022', '*')" |
How to urlencode a querystring in Python?,urllib.parse.quote_plus('string_of_characters_like_these:$#@=?%^Q^$') |
How to obscure a line behind a surface plot in matplotlib?,plt.show() |
How can I check if a checkbox is checked in Selenium Python Webdriver?,driver.find_element_by_name('<check_box_name>').is_selected() |
Convert UTF-8 with BOM to UTF-8 with no BOM in Python,s = u.encode('utf-8') |
create dictionary from list of variables,"dict((k, globals()[k]) for k in ('foo', 'bar'))" |
Hexagonal Self-Organizing map in Python,"(i + 1, j), (i - 1, j), (i, j - 1), (i, j + 1), (i - 1, j - 1), (i + 1, j - 1)" |
What's the most pythonic way of normalizing lineends in a string?,"mixed.replace('\r\n', '\n').replace('\r', '\n')" |
"How to make a python script which can logoff, shutdown, and restart a computer?","subprocess.call(['shutdown', '/r'])" |
"How to make a python script which can logoff, shutdown, and restart a computer?","subprocess.call(['shutdown', '/l '])" |
Efficient feature reduction in a pandas data frame,df['Features'] = df['Features'].apply(frozenset) |
Averaging the values in a dictionary based on the key,"[(i, sum(j) / len(j)) for i, j in list(d.items())]" |
How to split a string into integers in Python?,' \r 42\n\r \t\n \r0\n\r\n'.split() |
Python - converting a string of numbers into a list of int,"[int(s) for s in example_string.split(',')]" |
get count of values associated with key in dict python,sum(d['success'] for d in s) |
Transforming the string representation of a dictionary into a real dictionary,"dict(map(int, x.split(':')) for x in s.split(','))" |
pandas: how to do multiple groupby-apply operations,"df.groupby(level=0).agg(['sum', 'count', 'std'])" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.