text stringlengths 4 1.08k |
|---|
merge a pandas data frame `distancesdf` and column `dates` in pandas data frame `datesdf` into single,"pd.concat([distancesDF, datesDF.dates], axis=1)" |
identify groups of continuous numbers in a list,"[-2, -2, -2, -2, -8, -8, -8, -8, -8, -8]" |
how to read aloud python list comprehensions?,"[(x, y) for x in [1, 2, 3] for y in [3, 1, 4] if x != y]" |
improving performance of operations on a numpy array,"A.sum(axis=0, skipna=True)" |
python regex to match only first instance,"re.sub('-----.*?-----', '', data, 1)" |
is there a matplotlib equivalent of matlab's datacursormode?,"fig.canvas.mpl_connect('pick_event', self)" |
circular pairs from array?,"[(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 1)]" |
"real time face detection opencv, python","cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)" |
regular expression in python sentence extractor,"re.split('\\.\\s', text)" |
python- insert a character into a string,print(''.join(parts[1:])) |
how do i extract table data in pairs using beautifulsoup?,[[td.findNext(text=True) for td in tr.findAll('td')] for tr in rows] |
how to strip comma in python string,"s = s.replace(',', '')" |
"decoupled frontend and backend with django, webpack, reactjs, react-router","STATICFILES_DIRS = os.path.join(BASE_DIR, 'app')," |
transparent background in a tkinter window,root.geometry('+250+250') |
pandas: how to change all the values of a column?,df['Date'].str[-4:].astype(int) |
how to plot 2d math vectors with matplotlib?,plt.show() |
how to do pearson correlation of selected columns of a pandas data frame,"df.corr().ix[('special_col'), :-1]" |
iterate over matrices in numpy,"np.array(list(itertools.product([0, 1], repeat=n ** 2))).reshape(-1, n, n)" |
match regex pattern '((?:a|b|c)d)' on string 'bde',"re.findall('((?:A|B|C)D)', 'BDE')" |
implementing a popularity algorithm in django,Link.objects.all().order_by('-popularity') |
how to chose an aws profile when using boto3 to connect to cloudfront,dev = boto3.session.Session(profile_name='dev') |
setting up a learningratescheduler in keras,model.predict(X_test) |
how do i open files in python with variable as part of filename?,filename = 'C:\\Documents and Settings\\file' + str(i) + '.txt' |
can you plot live data in matplotlib?,plt.draw() |
how to replace all \w (none letters) with exception of '-' (dash) with regular expression?,"re.sub('[^-\\w]', ' ', 'black#white')" |
how to calculate mean in python?,numpy.mean(gp2) |
generate random utf-8 string in python,return ''.join(random.choice(alphabet) for i in range(length)) |
convert matlab engine array `x` to a numpy ndarray,np.array(x._data).reshape(x.size[::-1]).T |
"in tensorflow, how can i get nonzero values and their indices from a tensor with python?","[[0, 0], [1, 1]]" |
update json file,json_file.write('{}\n'.format(json.dumps(data))) |
remove line breaks from string `textblock` using regex,"re.sub('(?<=[a-z])\\r?\\n', ' ', textblock)" |
how to perform or condition in django queryset?,User.objects.filter(Q(income__gte=5000) | Q(income__isnull=True)) |
get the size of file 'c:\\python27\\lib\\genericpath.py',os.stat('C:\\Python27\\Lib\\genericpath.py').st_size |
find consecutive segments from a column 'a' in a pandas data frame 'df',df.reset_index().groupby('A')['index'].apply(np.array) |
"how to set a variable to be ""today's"" date in python/pandas",pandas.to_datetime('today') |
how can i tell if a file is a descendant of a given directory?,"os.path.commonprefix(['/the/dir/', os.path.realpath(filename)]) == '/the/dir/'" |
is there a simple way to switch between using and ignoring metacharacters in python regular expressions?,the_regex = re.compile(re.escape(the_value)) |
how to check if character in string is a letter? python,str.isalpha() |
django default foreign key value for users,"author = models.ForeignKey(User, null=True, blank=True)" |
Sort a nested list by two elements,"sorted(l, key=lambda x: (-int(x[1]), x[0]))" |
converting integer to list in python,[int(x) for x in str(num)] |
Converting byte string in unicode string,c.decode('unicode_escape') |
List of arguments with argparse,"parser.add_argument('-t', dest='table', help='', nargs='+')" |
How to convert a Date string to a DateTime object?,"datetime.datetime.strptime(s, '%Y-%m-%dT%H:%M:%SZ')" |
How to efficiently convert Matlab engine arrays to numpy ndarray?,np.array(x._data).reshape(x.size[::-1]).T |
Converting html to text with Python,"soup.get_text().replace('\n', '\n\n')" |
regex for repeating words in a string in Python,"re.sub('(?<!\\S)((\\S+)(?:\\s+\\2))(?:\\s+\\2)+(?!\\S)', '\\1', s)" |
Ordering a list of dictionaries in python,"mylist.sort(key=lambda d: (d['weight'], d['factor']))" |
Two Combination Lists from One List,itertools.combinations |
Creating a list of dictionaries in python,"[{'A': 1, 'C': 4, 'B': 2, 'D': 4}, {'A': 1, 'C': 4, 'B': 1, 'D': 5}]" |
How to zip lists in a list,"zip(*[[1, 2], [3, 4], [5, 6]])" |
How to display Image in pygame?,pygame.display.flip() |
Two Combination Lists from One List,"print([l[i:i + n] for i in range(len(l)) for n in range(1, len(l) - i + 1)])" |
Dynamic order in django-mptt,Comment.objects.all().order_by('-hotness') |
How to decode encodeURIComponent in GAE (python)?,urllib.parse.unquote('Foo%E2%84%A2%20Bar').decode('utf-8') |
Clamping floating numbers in Python?,"max(min(my_value, max_value), min_value)" |
How to binarize the values in a pandas DataFrame?,pd.get_dummies(df) |
How to extract all UPPER from a string? Python,"re.sub('[^A-Z]', '', s)" |
Python regular expression matching a multiline block of text,"re.compile('^(.+)\\n((?:\\n.+)+)', re.MULTILINE)" |
Convert float to comma-separated string,"""""""{0:,.2f}"""""".format(24322.34)" |
Get a list of values from a list of dictionaries in python,[d['key'] for d in l] |
How do I compare values in a dictionary?,"print(max(d, key=lambda x: (d[x]['salary'], d[x]['bonus'])))" |
How to extract the n-th elements from a list of tuples in python?,[x[1] for x in elements] |
Is it possible to get widget settings in Tkinter?,root.mainloop() |
How to convert dictionary into string,""""""""""""".join('{}{}'.format(key, val) for key, val in list(adict.items()))" |
convert double to float in Python,"struct.unpack('f', struct.pack('f', 0.00582811585976))" |
Select rows from a DataFrame based on values in a column in pandas,"df.loc[df.index.isin(['one', 'two'])]" |
plot data from CSV file with matplotlib,"ax1.plot(data['x'], data['y'], color='r', label='the data')" |
sorting a list of dictionary values by date in python,"list.sort(key=lambda item: item['date'], reverse=True)" |
How do I get a list of indices of non zero elements in a list?,"[i for i, e in enumerate(a) if e != 0]" |
Sort list of strings by integer suffix in python,"sorted(the_list, key=lambda x: int(x.split('_')[1]))" |
Pythonic way to get the largest item in a list,"max(a_list, key=operator.itemgetter(1))" |
How to create only one table with SQLAlchemy?,Base.metadata.tables['ticket_daily_history'].create(bind=engine) |
Parse_dates in Pandas,"df['date'] = pd.to_datetime(df['date'], format='%d%b%Y')" |
How can I add an element at the top of an OrderedDict in python?,"OrderedDict([('c', 3), ('e', 5), ('a', '1'), ('b', '2')])" |
sqlite3 in Python,c.execute('SELECT * FROM tbl') |
Selecting Element followed by text with Selenium WebDriver,"driver.find_element_by_xpath(""//li/label/input[contains(..,'polishpottery')]"")" |
"In Django, how do I filter based on all entities in a many-to-many relation instead of any?","Task.objects.exclude(prerequisites__status__in=['A', 'P', 'F'])" |
Find an element in a list of tuples,[item for item in a if item[0] == 1] |
python selenium click on button,driver.find_element_by_css_selector('.button.c_button.s_button').click() |
how to extract elements from a list in python?,"[a[i] for i in (1, 2, 5)]" |
How to count all elements in a nested dictionary?,sum(len(v) for v in food_colors.values()) |
How can I scroll a web page using selenium webdriver in python?,"driver.execute_script('window.scrollTo(0, document.body.scrollHeight);')" |
How to exclude a character from a regex group?,re.compile('[^a-zA-Z0-9-]') |
How can I plot hysteresis in matplotlib?,plt.show() |
How to make curvilinear plots in matplotlib,plt.show() |
is it possible to plot timelines with matplotlib?,plt.show() |
How to get output of exe in python script?,"output = subprocess.Popen(['mycmd', 'myarg'], stdout=PIPE).communicate()[0]" |
Converting a 3D List to a 3D NumPy array,"[[[4, 4, 4], [4, 4, 4], [4, 4, 4]], [[4], [4], [4]]]" |
What's the best way to search for a Python dictionary value in a list of dictionaries?,any(d['site'] == 'Superuser' for d in data) |
Replace non-ASCII characters with a single space,"re.sub('[^\\x00-\\x7F]+', ' ', text)" |
Find next sibling element in Python Selenium?,"driver.find_element_by_xpath(""//p[@id, 'one']/following-sibling::p"")" |
python pandas: apply a function with arguments to a series,"my_series.apply(your_function, args=(2, 3, 4), extra_kw=1)" |
Getting today's date in YYYY-MM-DD in Python?,datetime.datetime.today().strftime('%Y-%m-%d') |
Can I sort text by its numeric value in Python?,"sorted(list(mydict.items()), key=lambda a: map(int, a[0].split('.')))" |
How to convert a date string to different format,"datetime.datetime.strptime('2013-1-25', '%Y-%m-%d').strftime('%m/%d/%y')" |
How to convert a date string to different format,"datetime.datetime.strptime('2013-1-25', '%Y-%m-%d').strftime('%-m/%d/%y')" |
Python: sorting a dictionary of lists,"sorted(list(myDict.items()), key=lambda e: e[1][2])" |
How do I find an element that contains specific text in Selenium Webdriver (Python)?,"driver.find_elements_by_xpath(""//*[contains(text(), 'My Button')]"")" |
Selenium / Python - Selecting via css selector,"driver.find_element_by_css_selector("".test_button4[value='Update']"").click()" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.