text
stringlengths 4
1.08k
|
|---|
splitting dictionary/list inside a pandas column into separate columns,"pd.concat([df.drop(['b'], axis=1), df['b'].apply(pd.Series)], axis=1)"
|
in pandas dataframe with multiindex how can i filter by order?,"df.groupby(level=0, as_index=False).nth(0)"
|
seaborn plot including different distributions of the same data,"sns.pointplot(x='grp', y='val', hue='grp', data=df)"
|
converting a list of integers into range in python,"[(0, 4), (7, 9), (11, 11)]"
|
how to terminate process from python using pid?,"os.kill(pid, signal.SIGTERM)"
|
how to handle javascript alerts in selenium using python,driver.switch_to_alert().accept()
|
find the root of the git repository where the file lives,"os.path.abspath(os.path.join(dir, '..'))"
|
what's the proper way to write comparator as key in python 3 for sorting?,"print(sorted(l, key=lambda x: x))"
|
how do convert unicode escape sequences to unicode characters in a python string,name.decode('latin-1')
|
how do i include a boolean and within a regex?,"""""""(?=[MBDPI]{3})\\w*I\\w*"""""""
|
shuffling a list with restrictions in python,"[('a', '1'), ('b', '2'), ('c', '3'), ('d', '4')]"
|
delete an element 0 from a dictionary `a`,{i: a[i] for i in a if (i != 0)}
|
sort list of dictionaries by multiple keys with different ordering,"stats.sort(key=lambda x: (x['K'], x['B']), reverse=True)"
|
zip with list output instead of tuple,"[list(a) for a in zip([1, 2, 3], [4, 5, 6], [7, 8, 9])]"
|
how to extract a floating number from a string,"re.findall('[-+]?\\d*\\.\\d+|\\d+', 'Current Level: -13.2 db or 14.2 or 3')"
|
impregnate string with list entries - alternating,""""""""""""".join(chain.from_iterable(zip_longest(a, b, fillvalue='')))"
|
python convert unicode-hex utf-8 strings to unicode strings,s.encode('latin-1').decode('utf8')
|
how can i extract only text in scrapy selector in python,"site = hxs.select(""//h1[@class='state']/text()"")"
|
fastest way to convert an iterator to a list,list(your_iterator)
|
set environment variable 'debussy' to '1',os.environ['DEBUSSY'] = '1'
|
how to capture the entire string while using 'lookaround' with chars in regex?,"re.findall('\\b(?:b+a)+b+\\b', mystring)"
|
changing marker style in scatter plot according to third variable,plt.show()
|
how to get tuples from lists using list comprehension in python,"[(i, j) for i, j in zip(lst, lst2)]"
|
how to get alternating colours in dashed line using matplotlib?,plt.show()
|
in python: iterate over each string in a list,print(list(enumerate(words)))
|
set every two-stride far element to -1 starting from second element in array `a`,a[1::2] = -1
|
convert binary string to list of integers using python,"[s[i:i + 3] for i in range(0, len(s), 3)]"
|
merge two python pandas data frames of different length but keep all rows in output data frame,"df1.merge(df2, how='left', left_on='Column1', right_on='ColumnA')"
|
flask-jwt how handle a token?,xxxxx.yyyyy.zzzzz
|
create a dictionary `d` from list of key value pairs `iterable`,"d = {k: v for (k, v) in iterable}"
|
"update dictionary `b`, overwriting values where keys are identical, with contents of dictionary `d`",b.update(d)
|
how can i randomly place several non-colliding rects?,random.seed()
|
sort list `trial_list` based on values of dictionary `trail_dict`,"sorted(trial_list, key=lambda x: trial_dict[x])"
|
get alpha value `alpha` of a png image `img`,alpha = img.split()[-1]
|
python: splitting string by all space characters,"re.split('(?u)\\s', 'a\u200bc d')"
|
read lines containing integers from a file in python?,"a, b, c = (int(i) for i in line.split())"
|
python mysql.connector dictcursor?,cursor = db.cursor(dictionary=True)
|
get yesterday's date as a string in `yyyy-mm-dd` format using timedelta,(datetime.now() - timedelta(1)).strftime('%Y-%m-%d')
|
pythonically add header to a csv file,writer.writeheader()
|
square root scale using matplotlib/python,plt.show()
|
create an array where each element stores its indices,"np.moveaxis(np.indices((4, 5)), 0, -1)"
|
how to plot a gradient color line in matplotlib?,"plt.plot(x[i:i + 2], y[i:i + 2])"
|
normalize string `str` from 'cp1252' code to 'utf-8' code,print(str.encode('cp1252').decode('utf-8').encode('cp1252').decode('utf-8'))
|
how to overplot a line on a scatter plot in python?,plt.show()
|
find max overlap in list of lists,return [list(x) for x in list(results.values())]
|
how to read data from text file into array with python,"array = [[int(j) for j in i.split(',')] for i in tmp]"
|
create 2d numpy array from the data provided in 'somefile.csv' with each row in the file having same number of values,"X = numpy.loadtxt('somefile.csv', delimiter=',')"
|
check if string `needle` is in `haystack`,"if (needle in haystack):
|
pass"
|
how do i change the font size of the scale in matplotlib plots?,"ax.plot(x, y)"
|
how to make this for loop in python work?,print(alphs[:i] + alphs[i::-1])
|
is there a matplotlib flowable for reportlab?,matplotlib.use('PDF')
|
copy the content of file 'file.txt' to file 'file2.txt',"shutil.copy('file.txt', 'file2.txt')"
|
consuming a kinesis stream in python,time.sleep(1)
|
testing whether a numpy array contains a given row,"any(([1, 2] == x).all() for x in a)"
|
is there a way to set all values of a dictionary to zero?,"c = [(i, 0) for i in a]"
|
sort array `arr` in ascending order by values of the 3rd column,"arr[arr[:, (2)].argsort()]"
|
how do convert a pandas/dataframe to xml?,"print('\n'.join(df.apply(func, axis=1)))"
|
row-to-column transposition in python,"zip([1, 2, 3], [4, 5, 6])"
|
how to specify that a parameter is a list of specific objects in python docstrings,"type([1, 2, 3]) == type(['a', 'b', 'c'])"
|
"determine if 2 lists have the same elements, regardless of order?",sorted(x) == sorted(y)
|
removing control characters from a string in python,return ''.join(ch for ch in s if unicodedata.category(ch)[0] != 'C')
|
how to convert a list into a pandas dataframe,df['col1'] = df['col1'].apply(lambda i: ''.join(i))
|
how can i change the font size of ticks of axes object in matplotlib,plt.show()
|
"python, regex split and special character",l = re.compile('(\\s)').split(s)
|
adding custom fields to users in django,"middle_name = models.CharField(max_length=30, null=True, blank=True)"
|
similarity of lists in python - comparing customers according to their features,"[['100', '2', '3', '4'], ['110', '2', '5', '6'], ['120', '6', '3', '4']]"
|
finding sets of vectors that sum to zero,len(sum4) - np.count_nonzero(sum4)
|
sorting a tuple that contains tuples,"sorted(my_tuple, key=lambda tup: tup[1])"
|
sum of squares in a list in one line?,"sum(map(lambda x: x * x, l))"
|
how to get text for a root element using lxml?,print(etree.tostring(some_tag.find('strong')))
|
display `1 2 3` as a list of string,"print('[{0}, {1}, {2}]'.format(1, 2, 3))"
|
check if 'a' is in list `a`,('a' in a)
|
merging items in a list - python,"from functools import reduce
|
reduce(lambda x, y: 10 * x + y, [1, 2, 3, 4, 5])"
|
kill a running subprocess call,process.terminate()
|
elegant way to convert list to hex string,"hex(sum(b << i for i, b in enumerate(reversed(walls))))"
|
how to copy a dict and modify it in one line of code,"setup2 = dict(list(setup1.items()) + list({'param1': val10, 'param2': val20}.items()))"
|
how do i url encode in python?,urllib.parse.quote('http://spam.com/go/')
|
normalize a pandas dataframe `df` by row,"df.div(df.sum(axis=1), axis=0)"
|
pandas: keep only every row that has cumulated change by a threshold?,"pd.concat([df_slcd, signs], axis=1)"
|
python: finding a (string) key in a dictionary that contains a substring,"[(k, v) for k, v in D.items() if 'Light' in k]"
|
how to extract xml attribute using python elementtree,xml.find('./bar').attrib['key']
|
how to remove the space between subplots in matplotlib.pyplot?,ax.set_yticklabels([])
|
flask server cannot read file uploaded by post request,data = request.files['file'].read()
|
convert a list of characters into a string,""""""""""""".join(a)"
|
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]"
|
how to apply a function to a column in pandas depending on the value in another column?,"df['Words'] = df.apply(lambda row: func(row, 'Match Conflict'), axis=1)"
|
how to generate random number of given decimal point between 2 number in python?,"round(random.uniform(min_time, max_time), 1)"
|
how do you select choices in a form using python?,forms[3]['sex'] = ['male']
|
how do convert unicode escape sequences to unicode characters in a python string,print(name.decode('latin-1'))
|
sorting a defaultdict by value in python,"sorted(iter(cityPopulation.items()), key=lambda k_v: k_v[1][2], reverse=True)"
|
format a string `num` using string formatting,"""""""{0:.3g}"""""".format(num)"
|
how to merge two python dictionaries in a single expression?,"{k: v for d in dicts for k, v in list(d.items())}"
|
python: read json and loop dictionary,output_json = json.load(open('/tmp/output.json'))
|
delete first row of array `x`,"x = numpy.delete(x, 0, axis=0)"
|
how to find number of days in the current month,"print(calendar.monthrange(now.year, now.month)[1])"
|
print letter that appears most frequently in string `s`,print(collections.Counter(s).most_common(1)[0])
|
how to implement jump in pygame without sprites?,pygame.init()
|
replace nans by preceding values in pandas dataframe `df`,"df.fillna(method='ffill', inplace=True)"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.