text
stringlengths 4
1.08k
|
|---|
sort string `s` in lexicographic order,"sorted(sorted(s), key=str.upper)"
|
"flask, blue_print, current_app",app.run(debug=True)
|
easiest way to remove unicode representations from a string in python 3?,"print(re.sub('(\\\\u[0-9A-Fa-f]+)', unescapematch, 'Wi\\u2011Fi'))"
|
get absolute folder path and filename for file `existgdbpath `,os.path.split(os.path.abspath(existGDBPath))
|
pandas group by time windows,df.groupby(df['date_time'].apply(my_grouper))
|
generating an md5 checksum of a file,"print(hashlib.md5(open(full_path, 'rb').read()).hexdigest())"
|
convert ip address string to binary in python,print('.'.join([bin(int(x) + 256)[3:] for x in ip.split('.')]))
|
hex string to character in python,"""""""437c2123"""""".decode('hex')"
|
get column names from query result using pymssql,column_names = [item[0] for item in cursor.description]
|
python . how to get rid of '\r' in string?,open('test_newlines.txt').read().split()
|
format number using latex notation in python,print('\\num{{{0:.2g}}}'.format(1000000000.0))
|
numpy: find column index for element on each row,"array([0, 1, 2, 3], dtype=int64), array([1, 0, 1, 2], dtype=int64)"
|
divide the value for each key `k` in dict `d2` by the value for the same key `k` in dict `d1`,{k: (d2[k] / d1[k]) for k in list(d1.keys()) & d2}
|
convert binary string to numpy array,"np.fromstring('\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@', dtype='>f4')"
|
python - flatten a dict of lists into unique values?,"[k for k, g in groupby(sorted(chain.from_iterable(iter(content.values()))))]"
|
remove repeating characters from words,"re.sub('(.)\\1+', '\\1\\1', 'haaaaapppppyyy')"
|
python pandas: rename single column label in multi-index dataframe,"df.columns.set_levels(['one', 'two'], level=0, inplace=True)"
|
replacing all regex matches in single line,"re.sub('\\b(this|string)\\b', '<markup>\\1</markup>', 'this is my string')"
|
scrapy - follow rss links,xxs.select('//link/text()').extract()
|
limit how much data is read with numpy.genfromtxt for matplotlib,"numpy.genfromtxt('test.txt', skip_footer=2)"
|
how to use selenium with python?,mydriver.find_element_by_xpath(xpaths['submitButton']).click()
|
how do i convert a hex triplet to an rgb tuple and back?,"struct.unpack('BBB', rgbstr.decode('hex'))"
|
reading in integer from stdin in python,n = int(input())
|
plot a circle with pyplot,fig.savefig('plotcircles2.png')
|
how to convert spark rdd to pandas dataframe in ipython?,df.toPandas()
|
pandas replace values in dataframe timeseries,df = pd.DataFrame({'Close': [2.389000000001]})
|
python: how to redirect output with subprocess?,os.system(my_cmd)
|
how to add border around an image in opencv python,"cv2.imshow('image', im)"
|
check for a cookie with python flask,request.cookies.get('my_cookie')
|
how to get content of a small ascii file in python?,return f.read()
|
create a list of aggregation of each element from list `l2` to all elements of list `l1`,[(x + y) for x in l2 for y in l1]
|
how to create user from django shell,user.save()
|
how to write a memory efficient python program?,f.close()
|
converting integer to list in python,[int(x) for x in str(num)]
|
how to apply linregress in pandas bygroup,"linregress(df['col_X'], df['col_Y'])"
|
convert string to binary in python,"print(' '.join(format(ord(x), 'b') for x in a))"
|
get a new string including the first two characters of string `x`,x[:2]
|
how can i remove the fragment identifier from a url?,urlparse.urldefrag('http://www.address.com/something#something')
|
remove empty strings from list `str_list`,str_list = list([_f for _f in str_list if _f])
|
how to pass a bash variable to python?,sys.exit(1)
|
what's the simplest way of detecting keyboard input in python from the terminal?,"termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)"
|
get pandas groupby object with sum over the rows with same column names within dataframe `df`,"df.groupby(df.columns, axis=1).sum()"
|
pandas: aggregate based on filter on another column,"df.groupby(['Month', 'Fruit']).sum().unstack(level=0)"
|
matplotlib diagrams with 2 y-axis,"ax2.set_ylabel('name2', fontsize=14, color='blue')"
|
validate a filename in python,os.path.normpath('(path-to-wiki)/foo/bar.txt').startswith('(path-to-wiki)')
|
how do you set up a flask application with sqlalchemy for testing?,app.run(debug=True)
|
python: confusions with urljoin,"urljoin('some', 'thing')"
|
python pandas drop columns based on max value of column,df.max()
|
how does python know to add a space between a string literal and a variable?,print(str(a) + ' plus ' + str(b) + ' equals ' + str(a + b))
|
python matplotlib - smooth plot line for x-axis with date values,fig.show()
|
reverse a list `array`,list(reversed(array))
|
extract text from webpage using selenium in python,driver.get('https://www.sunnah.com/bukhari/5')
|
print function in python,"print(' '.join('%s=%s' % (k, v) for v, k in input))"
|
make new column in panda dataframe by adding values from other columns,df['C'] = df['A'] + df['B']
|
get a list of pairs of key-value sorted by values in dictionary `data`,"sorted(list(data.items()), key=lambda x: x[1])"
|
python: deleting numbers in a file,"fin = open('C:\\folder1\\test1.txt', 'r')"
|
how to find values from one dataframe in another using pandas?,"print(pd.merge(df1, df2, on='B'))"
|
how to remove multiple columns that end with same text in pandas?,"df2 = df.ix[:, (~df.columns.str.endswith('prefix'))]"
|
how to calculate a column in a row using two columns of the previous row in spark data frame?,"df.select('*', current_population).show()"
|
"python string formatting when string contains ""%s"" without escaping","""""""Day old bread, 50% sale {0}"""""".format('today')"
|
insert row into excel spreadsheet using openpyxl in python,wb.save(file)
|
find maximum value of a column and return the corresponding row values using pandas,df.loc[df['Value'].idxmax()]
|
how to binarize the values in a pandas dataframe?,pd.get_dummies(df)
|
how to get a random value in python dictionary,random.choice(list(d.keys()))
|
how to expire session due to inactivity in django?,request.session['last_activity'] = datetime.now()
|
calling a function from string inside the same module in python?,func()
|
python check if all of the following items is in a list,"set(l).issuperset(set(['a', 'b']))"
|
get last day of the first month in 2002,"calendar.monthrange(2002, 1)"
|
changing user in python,"os.system('su hadoop -c ""bin/hadoop-daemon.sh stop tasktracker""')"
|
extract floating point numbers from a string 'current level: -13.2 db or 14.2 or 3',"re.findall('[-+]?\\d*\\.\\d+|\\d+', 'Current Level: -13.2 db or 14.2 or 3')"
|
how can i view a text representation of an lxml element?,"print(etree.tostring(root, pretty_print=True))"
|
how to count values in a certain range in a numpy array?,"numpy.histogram(a, bins=(25, 100))"
|
how to read typical function documentation in python?,"Pool(processes=None, initializer=None, initargs=(), maxtasksperchild=None)"
|
how do i remove identical items from a list and sort it in python?,my_list.sort()
|
sort list `a` in ascending order based on the addition of the second and third elements of each tuple in it,"sorted(a, key=lambda x: (sum(x[1:3]), x[0]))"
|
key to maxima of dictionary in python,"['e', 'f']"
|
extracting only characters from a string in python,"re.split('[^a-zA-Z]*', 'your string')"
|
how to get column by number in pandas?,df[[1]]
|
python: anyway to use map to get first element of a tuple,print([x[0] for x in data])
|
"python - finding the user's ""downloads"" folder","return os.path.join(home, 'Downloads')"
|
remove items from dictionary `mydict` if the item's value `val` is equal to 42,"myDict = {key: val for key, val in list(myDict.items()) if val != 42}"
|
list comprehension replace for loop in 2d matrix,[int(x) for line in data for x in line.split()]
|
how can i add the corresponding elements of several lists of numbers?,"map(sum, zip(*lists))"
|
how to create a list or tuple of empty lists in python?,result = [list(someListOfElements) for _ in range(x)]
|
"how do i turn a python datetime into a string, with readable format date?","my_datetime.strftime('%B %d, %Y')"
|
reset index of series `s`,s.reset_index(0).reset_index(drop=True)
|
is there a way to use ribbon toolbars in tkinter?,"root.grid_rowconfigure(1, weight=1)"
|
pandas: counting unique values in a dataframe,d.stack().groupby(level=0).apply(pd.Series.value_counts).unstack().fillna(0)
|
"python: how to ""fork"" a session in django","return render(request, 'myapp/subprofile_select.html', {'form': form})"
|
python: split on either a space or a hyphen?,"re.split('[\\s-]+', text)"
|
sort list `your_list` by the `anniversary_score` attribute of each object,your_list.sort(key=lambda x: x.anniversary_score)
|
how can i tail a log file in python?,time.sleep(1)
|
python pandas dataframe: retrieve number of columns,len(df.index)
|
delete the element 6 from list `a`,a.remove(6)
|
check if string ends with one of the strings from a list,"""""""test.mp3"""""".endswith(('.mp3', '.avi'))"
|
how to unzip a list of tuples into individual lists?,zip(*l)
|
argparse: how to accept any number of optional arguments (starting with `-` or `--`),print(parser.parse_args('--foo B cmd --arg1 XX ZZ --foobar'.split()))
|
efficient way to apply multiple filters to pandas dataframe or series,df[(df['col1'] >= 1) & (df['col1'] <= 1)]
|
replace exact substring in python,"re.sub('\\bin\\b', '', 'office administration in delhi')"
|
how to sort a large dictionary,"['002', '020', 'key', 'value']"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.