text
stringlengths 4
1.08k
|
|---|
Merge DataFrames in Pandas using the mean,"pd.concat((df1, df2), axis=1).mean(axis=1)"
|
Average values in two Numpy arrays,"np.mean(np.array([old_set, new_set]), axis=0)"
|
Changing marker's size in matplotlib,"scatter(x, y, s=500, color='green', marker='h')"
|
split items in list,"result = [item for word in words for item in word.split(',')]"
|
Converting JSON date string to python datetime,"datetime.datetime.strptime('2012-05-29T19:30:03.283Z', '%Y-%m-%dT%H:%M:%S.%fZ')"
|
python comprehension loop for dictionary,sum(item['one'] for item in list(tadas.values()))
|
How to base64 encode a PDF file in Python,"a = open('pdf_reference.pdf', 'rb').read().encode('base64')"
|
split a string in python,a.rstrip().split('\n')
|
split a string in python,a.split('\n')[:-1]
|
How can I return HTTP status code 204 from a Django view?,return HttpResponse(status=204)
|
check if a value exist in a list,(7 in a)
|
check if a value exist in a list,('a' in a)
|
Sorting JSON data by keys value,"sorted(results, key=itemgetter('year'))"
|
How do I get current URL in Selenium Webdriver 2 Python?,print(browser.current_url)
|
Python: Split string with multiple delimiters,"re.split('; |, ', str)"
|
Unescaping Characters in a String with Python,"""""""\\u003Cp\\u003E"""""".decode('unicode-escape')"
|
Convert string date to timestamp in Python,"time.mktime(datetime.datetime.strptime(s, '%d/%m/%Y').timetuple())"
|
Convert string date to timestamp in Python,"int(datetime.datetime.strptime('01/12/2011', '%d/%m/%Y').strftime('%s'))"
|
How to get http headers in flask?,request.headers['your-header-name']
|
How to subset a data frame using Pandas based on a group criteria?,df.groupby('User')['X'].filter(lambda x: x.sum() == 0)
|
How to subset a data frame using Pandas based on a group criteria?,df.loc[df.groupby('User')['X'].transform(sum) == 0]
|
How to subset a data frame using Pandas based on a group criteria?,df.groupby('User')['X'].transform(sum) == 0
|
How do I find an element that contains specific text in Selenium Webdriver (Python)?,"driver.find_elements_by_xpath(""//*[contains(text(), 'My Button')]"")"
|
Convert pandas group by object to multi-indexed Dataframe,"df.set_index(['Name', 'Destination'])"
|
How do I coalesce a sequence of identical characters into just one?,"print(re.sub('(\\W)\\1+', '\\1', a))"
|
How to open a file with the standard application?,"os.system('start ""$file""')"
|
Convert a Unicode string to a string,"unicodedata.normalize('NFKD', title).encode('ascii', 'ignore')"
|
Convert a Unicode string to a string,"a.encode('ascii', 'ignore')"
|
Get a filtered list of files in a directory,"files = [f for f in os.listdir('.') if re.match('[0-9]+.*\\.jpg', f)]"
|
Adding a 1-D Array to a 3-D array in Numpy,"np.zeros((6, 9, 20)) + np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])[(None), :, (None)]"
|
Adding a 1-D Array to a 3-D array in Numpy,"np.zeros((6, 9, 20)) + np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]).reshape((1, 9, 1))"
|
How can I launch an instance of an application using Python?,os.system('start excel.exe <path/to/file>')
|
What is the proper way to print a nested list with the highest value in Python,"print(max(x, key=sum))"
|
Functional statement in Python to return the sum of certain lists in a list of lists,sum(len(y) for y in x if len(y) > 1)
|
Python - Insert numbers in string between quotes,"re.sub('(\\d+)', '""\\1""', 'This is number 1 and this is number 22')"
|
Multiplying Rows and Columns of Python Sparse Matrix by elements in an Array,"numpy.dot(numpy.dot(a, m), a)"
|
How to check if something exists in a postgresql database using django?,"Entry.objects.filter(name='name', title='title').exists()"
|
Sort a nested list by two elements,"sorted(l, key=lambda x: (-int(x[1]), x[0]))"
|
Django - How to simply get domain name?,request.META['HTTP_HOST']
|
Python Regex Get String Between Two Substrings,"re.findall(""api\\('(.*?)'"", ""api('randomkey123xyz987', 'key', 'text')"")"
|
Call Perl script from Python,"subprocess.call(['/usr/bin/perl', './uireplace.pl', var])"
|
Pythonic way to print list items,print('\n'.join(str(p) for p in myList))
|
update dictionary with dynamic keys and values in python,mydic.update({i: o['name']})
|
how to split a unicode string into list,list(stru.decode('utf-8'))
|
Convert UTF-8 with BOM to UTF-8 with no BOM in Python,u = s.decode('utf-8-sig')
|
How do I do a not equal in Django queryset filtering?,Entry.objects.filter(~Q(id=3))
|
How can I lookup an attribute in any scope by name?,"getattr(__builtins__, 'range')"
|
"How to make a python script which can logoff, shutdown, and restart a computer?","subprocess.call(['shutdown', '/r', '/t', '900'])"
|
"How to make a python script which can logoff, shutdown, and restart a computer?","subprocess.call(['shutdown', '/s'])"
|
"How to make a python script which can logoff, shutdown, and restart a computer?","subprocess.call(['shutdown', '/a '])"
|
"How to make a python script which can logoff, shutdown, and restart a computer?","subprocess.call(['shutdown', '/l '])"
|
"How to make a python script which can logoff, shutdown, and restart a computer?","subprocess.call(['shutdown', '/r'])"
|
How to erase the file contents of text file in Python?,"open('filename', 'w').close()"
|
How to erase the file contents of text file in Python?,"open('file.txt', 'w').close()"
|
Pandas DataFrame to List of Dictionaries,df.to_dict('index')
|
Pandas DataFrame to List of Dictionaries,df.to_dict('records')
|
pandas dataframe groupby datetime month,df.groupby(pd.TimeGrouper(freq='M'))
|
How do I divide the members of a list by the corresponding members of another list in Python?,"[(c / t) for c, t in zip(conversions, trials)]"
|
sort dict by value python,"sorted(data, key=data.get)"
|
sort dict by value python,sorted(data.values())
|
sort dict by value python,"sorted(list(data.items()), key=lambda x: x[1])"
|
sort dict by value python,"sorted(list(data.items()), key=lambda x: x[1])"
|
How do I display current time using Python + Django?,now = datetime.datetime.now().strftime('%H:%M:%S')
|
Find the nth occurrence of substring in a string,"""""""foo bar bar bar"""""".replace('bar', 'XXX', 1).find('bar')"
|
How do you check the presence of many keys in a Python dictinary?,"set(['stackoverflow', 'google']).issubset(sites)"
|
Replace part of a string in Python?,"stuff.replace(' and ', '/')"
|
How to use `numpy.savez` in a loop for save more than one array?,"np.savez(tmp, *[getarray[0], getarray[1], getarray[8]])"
|
time offset,"t = datetime.datetime.now()
|
(t - datetime.timedelta(hours=1, minutes=10))"
|
time offset,"(t - datetime.timedelta(hours=1, minutes=10))"
|
time offset,"dt = datetime.datetime.combine(datetime.date.today(), t)"
|
time offset,dt -= datetime.timedelta(hours=5)
|
Manipulating binary data in Python,print(data.encode('hex'))
|
Manipulating binary data in Python,print(' '.join([str(ord(a)) for a in data]))
|
python - iterating over a subset of a list of tuples,[x for x in l if x[1] == 1]
|
How to read stdin to a 2d python array of integers?,a.fromlist([int(val) for val in stdin.read().split()])
|
Is there a way to refer to the entire matched expression in re.sub without the use of a group?,"print(re.sub('[_%^$]', '\\\\\\g<0>', line))"
|
How to use regular expression in lxml xpath?,"doc.xpath(""//a[starts-with(text(),'some text')]"")"
|
Compare elements of a list of lists and return a list,zip(*a)
|
Convert list of strings to int,"[map(int, sublist) for sublist in lst]"
|
Convert list of strings to int,[[int(x) for x in sublist] for sublist in lst]
|
Numpy: find index of elements in one array that occur in another array,"np.where(np.in1d(A, B))[0]"
|
Split dictionary of lists into list of dictionaries,"[{'key1': a, 'key2': b} for a, b in zip(d['key1'], d['key2'])]"
|
Split dictionary of lists into list of dictionaries,"map(dict, zip(*[[(k, v) for v in value] for k, value in list(d.items())]))"
|
Get Last Day of the Month,"calendar.monthrange(2002, 1)"
|
Get Last Day of the Month,"calendar.monthrange(2008, 2)"
|
Get Last Day of the Month,"calendar.monthrange(2100, 2)"
|
Get Last Day of the Month,"calendar.monthrange(year, month)[1]"
|
Get Last Day of the Month,"monthrange(2012, 2)"
|
Get Last Day of the Month,"(datetime.date(2000, 2, 1) - datetime.timedelta(days=1))"
|
Calling an external command,from subprocess import call
|
Calling an external command,os.system('some_command with args')
|
Calling an external command,os.system('some_command < input_file | another_command > output_file')
|
Calling an external command,stream = os.popen('some_command with args')
|
Calling an external command,"print(subprocess.Popen('echo Hello World', shell=True, stdout=subprocess.PIPE).stdout.read())"
|
Calling an external command,print(os.popen('echo Hello World').read())
|
Calling an external command,"return_code = subprocess.call('echo Hello World', shell=True)"
|
Calling an external command,"call(['ls', '-l'])"
|
Url decode UTF-8 in Python,print(urllib.parse.unquote(url).decode('utf8'))
|
Url decode UTF-8 in Python,url = urllib.parse.unquote(url).decode('utf8')
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.