text
stringlengths 4
1.08k
|
|---|
select rows whose column value in column `column_name` does not equal `some_value` in pandas data frame,df.loc[df['column_name'] != some_value]
|
transform time series `df` into a pivot table aggregated by column 'close' using column `df.index.date` as index and values of column `df.index.time` as columns,"pd.pivot_table(df, index=df.index.date, columns=df.index.time, values='Close')"
|
how can i handle an alert with ghostdriver via python?,driver.execute_script('window.confirm = function(){return true;}')
|
web scraping with python,print(soup.prettify())
|
joining a list that has integer values with python,"print(', '.join(str(x) for x in list_of_ints))"
|
deleting key/value from list of dictionaries using lambda and map,"map(lambda d: d.pop('k1'), list_of_d)"
|
sorting dictionary keys in python,"sorted(d, key=d.get)"
|
why are literal formatted strings so slow in python 3.6 alpha? (now fixed in 3.6 stable),""""""""""""".join(['X is ', x.__format__('')])"
|
how to convert triangle matrix to square in numpy?,"np.where(np.triu(np.ones(A.shape[0], dtype=bool), 1), A.T, A)"
|
python convert a list of float to string,['{:.2f}'.format(x) for x in nums]
|
finding duplicates in a list of lists,"sorted(map(list, list(totals.items())))"
|
convert a string representation of a dictionary to a dictionary?,"ast.literal_eval(""{'muffin' : 'lolz', 'foo' : 'kitty'}"")"
|
"format string `hello {name}, how are you {name}, welcome {name}` to be interspersed by `name` three times, specifying the value as `john` only once","""""""hello {name}, how are you {name}, welcome {name}"""""".format(name='john')"
|
how can i log outside of main flask module?,app.run()
|
storing an array of integers with django,"eval('[1,2,3,4]')"
|
replace one item in a string with one item from a list,"list(replace([1, 2, 3, 2, 2, 3, 1, 2, 4, 2], to_replace=2, fill='apple'))"
|
divide the values with same keys of two dictionary `d1` and `d2`,{k: (float(d2[k]) / d1[k]) for k in d2}
|
python: mysqldb. how to get columns name without executing select * in a big table?,cursor.execute('SELECT * FROM table_name WHERE 1=0')
|
multiple plot in one figure in python,plt.show()
|
area intersection in python,plt.show()
|
python: sorting dictionary of dictionaries,"sorted(dic, key=lambda x: dic[x].get('Fisher', float('inf')))"
|
is there a function in python to split a word into a list?,"['W', 'o', 'r', 'd', ' ', 't', 'o', ' ', 'S', 'p', 'l', 'i', 't']"
|
how to make matrices in python?,print('\n'.join([' '.join(row) for row in matrix]))
|
find float number proceeding sub-string `par` in string `dir`,"float(re.findall('(?:^|_)' + par + '(\\d+\\.\\d*)', dir)[0])"
|
sort a string `s` in lexicographic order,"sorted(s, key=str.upper)"
|
python: how can i find all files with a particular extension?,glob.glob('?.gif')
|
python: download a file over an ftp server,"urllib.request.urlretrieve('ftp://server/path/to/file', 'file')"
|
how to test that matplotlib's show() shows a figure without actually showing it?,matplotlib.use('Template')
|
how to remove whitespace in beautifulsoup,"re.sub('[\\ \\n]{2,}', '', yourstring)"
|
"using python's datetime module, get the year that utc-11 is currently in",(datetime.datetime.utcnow() - datetime.timedelta(hours=11)).year
|
"efficiently re-indexing one level with ""forward-fill"" in a multi-index dataframe",df1['value'].unstack(0).asfreq('D').ffill()
|
"insert ' ' between every three digit before '.' and replace ',' with '.' in 12345678.46","format(12345678.46, ',').replace(',', ' ').replace('.', ',')"
|
how can i configure pyramid's json encoding?,return Response(json_string)
|
sum of product of combinations in a list,"sum([(i * j) for i, j in list(itertools.combinations(l, 2))])"
|
remove all occurrences of words in a string from a python list,""""""" """""".join([i for i in word_list if i not in remove_list])"
|
how do i rename columns in a python pandas dataframe?,"country_data_table.rename(columns={'value': country.name}, inplace=True)"
|
how can i vectorize the averaging of 2x2 sub-arrays of numpy array?,y.mean(axis=1).mean(axis=-1)
|
how to transform a tuple to a string of values without comma and parentheses,""""""""""""".join(str(i) for i in (34.2424, -64.2344, 76.3534, 45.2344))"
|
how to merge two dataframes into single matching the column values,"pd.concat([distancesDF, datesDF.dates], axis=1)"
|
split a list of strings at positions they match a different list of strings,"re.split('|'.join(re.escape(x) for x in list1), s)"
|
how to sum a 2d array in python?,"sum(map(sum, a))"
|
python - use list as function parameters,some_func(*params)
|
"convert pandas dataframe `df` with fields 'id', 'value' to dictionary",df.set_index('id')['value'].to_dict()
|
how to decode an invalid json string in python,"demjson.decode('{ hotel: { id: ""123"", name: ""hotel_name""} }')"
|
import module from string variable,importlib.import_module('matplotlib.text')
|
calling a function of a module from a string with the function's name in python,locals()['myfunction']()
|
two values from one input in python?,"var1, var2 = input('enter two numbers:').split(' ')"
|
how to search for a word and then replace text after it using regular expressions in python?,"re.sub('(<form.*?action="")([^""]+)', '\\1newlogin.php', content)"
|
cherrypy interferes with twisted shutting down on windows,cherrypy.engine.start()
|
how to add http headers to a packet sniffed using scapy,del pkt[TCP].chksum
|
loading and parsing a json file with multiple json objects in python,data.append(json.loads(line))
|
changing tick label line spacing in matplotlib,plt.show()
|
format datetime in `dt` as string in format `'%m/%d/%y`,dt.strftime('%m/%d/%Y')
|
"list of tuples (string, float)with nan how to get the min value?","min([t for t in l if not math.isnan(t[1])], key=itemgetter(1))"
|
elegant way to extract a tuple from list of tuples with minimum value of element,min([x[::-1] for x in a])[::-1]
|
sort a sublist of elements in a list leaving the rest in place,"['X', 'B', 'B1', 'B11', 'B2', 'B22', 'C', 'Q1', 'C11', 'C2', 'B21']"
|
getting the first elements per row in an array in python?,zip(*s)[0]
|
finding recurring patterns in a string,"re.findall('^(.+?)((.+)\\3+)$', '42344343434')[0][:-1]"
|
django - unique_together change - any danger in prod db?,MyModel.objects.filter(title__exact='')
|
matrix multiplication in pandas,"np.dot(x, y)"
|
string.lower in python 3,"""""""FOo"""""".lower()"
|
"regular expression syntax for ""match nothing""?",re.compile('.\\A|.\\A*|.\\A+')
|
pandas split string into columns,"df['stats'].str[1:-1].str.split(',', expand=True).astype(float)"
|
convert list of strings `str_list` into list of integers,[int(i) for i in str_list]
|
selenium get the entire `driver` page text,driver.page_source
|
image library for python 3,img.save('output.png')
|
how to place minor ticks on symlog scale?,plt.show()
|
"python, remove all non-alphabet chars from string",""""""""""""".join([i for i in s if i.isalpha()])"
|
extract the first four rows of the column `id` from a pandas dataframe `df`,df.groupby('ID').head(4)
|
how to show the whole image when using opencv warpperspective,im = cv2.imread('image1.png')
|
abort a list comprehension,[(x ** 2) for x in range(10)]
|
pandas groupby: how to get a union of strings,df.groupby('A').apply(f)
|
"how to print a list in python ""nicely""",pprint(the_list)
|
lowercase string values with key 'content' in a list of dictionaries `messages`,[{'content': x['content'].lower()} for x in messages]
|
get line count of file `filename`,"def bufcount(filename):
|
f = open(filename)
|
lines = 0
|
buf_size = (1024 * 1024)
|
read_f = f.read
|
buf = read_f(buf_size)
|
while buf:
|
lines += buf.count('\n')
|
buf = read_f(buf_size)
|
return lines"
|
how do i sort unicode strings alphabetically in python?,"sorted(['a', 'b', 'c', '\xc3\xa4'])"
|
"writing a ""table"" from python3","write('Temperature is {0} and pressure is {1})'.format(X, Y))"
|
is there a scala equivalent to python's list comprehension,list.filter(_ != somevalue)
|
how to combine two list containing dictionary with similar keys?,"result = [{k: (d1[k] + d2[k]) for k in d1} for d1, d2 in zip(var1, var2)]"
|
create a list of all unique characters in string 'aaabcabccd',""""""""""""".join(list(OrderedDict.fromkeys('aaabcabccd').keys()))"
|
python/matplotlib - is there a way to make a discontinuous axis?,ax2.yaxis.tick_right()
|
"select rows whose value of the ""b"" column is ""one"" or ""three"" in the dataframe `df`","print(df.loc[df['B'].isin(['one', 'three'])])"
|
simple way to convert list to dict,dict(i.split('=') for i in x)
|
how to initialize multiple columns to existing pandas dataframe,"pd.concat([df, pd.DataFrame(0, df.index, list('cd'))], axis=1)"
|
most idiomatic way to provide default value in python?,myval = myval if myval is not None else defaultval
|
organizing list of tuples,l = list(set(l))
|
"searching if the values on a list is in the dictionary whose format is key-string, value-list(strings)","[key for item in lst for key, value in list(my_dict.items()) if item in value]"
|
matplotlib colorbar formatting,cb.ax.yaxis.set_major_formatter(plt.FuncFormatter(myfmt))
|
python lxml/beautiful soup to find all links on a web page,urls = html.xpath('//a/@href')
|
"detect holes, ends and beginnings of a line using opencv?",cv2.waitKey(0)
|
how can i convert a string to an int in python?,return float(a) / float(b)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.