neulab/docprompting-conala huggingface dataset:
# Get pandas GroupBy object with sum over the rows with same column names within  dataframe `df`
df.groupby(df.columns, axis=1).sum()
# 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}
# combining rows in pandas by adding their values
df.groupby(df.index).sum()
# make all keys lowercase in dictionary `d`
d = {(a.lower(), b): v for (a, b), v in list(d.items())}
# create a dataframe `d` filled with zeros with indices from 0 to length of `data` and column names from `feature_list`
d = pd.DataFrame(0, index=np.arange(len(data)), columns=feature_list)
# get a dict of variable names `['some', 'list', 'of', 'vars']` as a string and their values
dict((name, eval(name)) for name in ['some', 'list', 'of', 'vars'])
# Format a date object `str_data` into iso fomrat
datetime.datetime.strptime(str_date, '%m/%d/%Y').date().isoformat()
# sort dictionary `mydict` in descending order based on the sum of each value in it
sorted(iter(mydict.items()), key=lambda tup: sum(tup[1]), reverse=True)[:3]
# get top `3` items from a dictionary `mydict` with largest sum of values
heapq.nlargest(3, iter(mydict.items()), key=lambda tup: sum(tup[1]))
# calculate the md5 checksum of a file named  'filename.exe'
hashlib.md5(open('filename.exe', 'rb').read()).hexdigest()
# get max key in dictionary `MyCount`
max(list(MyCount.keys()), key=int)
# return a string from a regex match with pattern '<img.*?>' in string 'line'
imtag = re.match('<img.*?>', line).group(0)
# In Django, filter `Task.objects` based on all entities in ['A', 'P', 'F']
Task.objects.exclude(prerequisites__status__in=['A', 'P', 'F'])
# remove duplicated items from list of lists `testdata`
list(map(list, set(map(lambda i: tuple(i), testdata))))
# uniqueness for list of lists `testdata`
[list(i) for i in set(tuple(i) for i in testdata)]
# download file from http url `file_url`
file_name = wget.download(file_url)
# produce a pivot table as dataframe using column 'Y' in datafram `df` to form the axes of the resulting dataframe
df.pivot_table('Y', rows='X', cols='X2')
# remove duplicate dict in list `l`
[dict(t) for t in set([tuple(d.items()) for d in l])]
# request url 'https://www.reporo.com/' without verifying SSL certificates
requests.get('https://www.reporo.com/', verify=False)
# Filter queryset for all objects in Django model `MyModel` where texts length are greater than `254`
MyModel.objects.filter(text__regex='^.{254}.*')
# Get value for  "username" parameter in GET request  in Django
request.GET.get('username', '')
# convert binary string '\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@' to numpy array
np.fromstring('\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@', dtype='<f4')
# convert binary string to numpy array
np.fromstring('\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@', dtype='>f4')
# convert a pandas `df1` groupby object to dataframe
DataFrame({'count': df1.groupby(['Name', 'City']).size()}).reset_index()
# lowercase keys and values in dictionary `{'My Key': 'My Value'}`
{k.lower(): v.lower() for k, v in list({'My Key': 'My Value'}.items())}
# lowercase all keys and values in dictionary `{'My Key': 'My Value'}`
dict((k.lower(), v) for k, v in {'My Key': 'My Value'}.items())
# Convert each key,value pair in a dictionary `{'My Key': 'My Value'}` to lowercase
dict((k.lower(), v.lower()) for k, v in {'My Key': 'My Value'}.items())
# get logical xor of `a` and `b`
(bool(a) != bool(b))
# get logical xor of `a` and `b`
(bool(a) ^ bool(b))
# get logical xor of `a` and `b`
xor(bool(a), bool(b))
# get the logical xor of two variables `str1` and `str2`
return (bool(str1) ^ bool(str2))
# Django check if an object with criteria `name` equal to 'name' and criteria `title` equal to 'title' exists in model `Entry`
Entry.objects.filter(name='name', title='title').exists()
# get the date 6 months from today
six_months = (date.today() + relativedelta(months=(+ 6)))
# calculate the date six months from the current date
print((datetime.date.today() + datetime.timedelta(((6 * 365) / 12))).isoformat())
# apply itertools.product to elements of a list of lists `arrays`
list(itertools.product(*arrays))
# call a Python script "test2.py"
exec(compile(open('test2.py').read(), 'test2.py', 'exec'))
# filter dataframe `df` by sub-level index '0630' in pandas
df[df.index.map(lambda x: x[1].endswith('0630'))]
# Load the url `http://www.google.com` in selenium webdriver `driver`
driver.get('http://www.google.com')
# convert a 3d array `img` of dimensions 4x2x3 to a 2d array   of dimensions 3x8
img.transpose(2, 0, 1).reshape(3, -1)
# format datetime in `dt` as string in format `'%m/%d/%Y`
dt.strftime('%m/%d/%Y')
# concatenate a list of numpy arrays `input_list` together into a flattened list of values
np.concatenate(input_list).ravel().tolist()
# set an array of unicode characters `[u'\xe9', u'\xe3', u'\xe2']` as labels in Matplotlib `ax`
ax.set_yticklabels(['\xe9', '\xe3', '\xe2'])
# find all files with extension '.c' in directory `folder`
results += [each for each in os.listdir(folder) if each.endswith('.c')]
# check if a local variable 'myVar' exists
if ('myVar' in locals()):
    pass
# check if a global variable 'myVar' exists
if ('myVar' in globals()):
    pass
# get a list of tuples of every three consecutive items in list `[1, 2, 3, 4, 5, 6, 7, 8, 9]`
list(zip(*((iter([1, 2, 3, 4, 5, 6, 7, 8, 9]),) * 3)))
# read an excel file 'ComponentReport-DJI.xls'
open('ComponentReport-DJI.xls', 'rb').read(200)
# create a new 2D array with 2 random rows from array `A`
A[(np.random.choice(A.shape[0], 2, replace=False)), :]
# create a new 2 dimensional array containing two random rows from array `A`
A[(np.random.randint(A.shape[0], size=2)), :]
# Create an array containing the conversion of string '100110' into separate elements
np.array(map(int, '100110'))
# convert a string 'mystr' to numpy array of integer values
print(np.array(list(mystr), dtype=int))
# print letter that appears most frequently in string `s`
print(collections.Counter(s).most_common(1)[0])
# match the pattern '[:;][)(](?![)(])' to the string `str`
re.match('[:;][)(](?![)(])', str)
# execute file 'filename.py'
exec(compile(open('filename.py').read(), 'filename.py', 'exec'))
# select records of dataframe `df` where the sum of column 'X' for each value in column 'User' is 0
df.groupby('User')['X'].filter(lambda x: x.sum() == 0)
# Find all records from collection `collection` without extracting mongo id `_id`
db.collection.find({}, {'_id': False})
# find the magnitude (length) squared of a vector `vf` field
np.einsum('...j,...j->...', vf, vf)
# Get `3` unique items from a list
random.sample(list(range(1, 16)), 3)
# convert string of bytes `y\xcc\xa6\xbb` into an int
struct.unpack('<L', 'y\xcc\xa6\xbb')[0]
# get a list of all integer points in a `dim` dimensional hypercube with coordinates from `-x` to `y` for all dimensions
list(itertools.product(list(range(-x, y)), repeat=dim))
# extract data field 'bar' from json object
json.loads('{"foo": 42, "bar": "baz"}')['bar']
# pandas subtract a row from dataframe `df2` from dataframe `df`
pd.DataFrame(df.values - df2.values, columns=df.columns)
# update the `globals()` dictionary with the contents of the `vars(args)` dictionary
globals().update(vars(args))
# convert a string of date strings `date_stngs ` to datetime objects and put them in a dataframe
pd.to_datetime(pd.Series(date_stngs))
# Formate current date and time to a string using pattern '%Y-%m-%d %H:%M:%S'
datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# combine two dictionaries `d ` and `d1`, concatenate string values with identical `keys`
dict((k, d.get(k, '') + d1.get(k, '')) for k in keys)
# generate pdf file `output_filename` from markdown file `input_filename`
with open(input_filename, 'r') as f:
    html_text = markdown(f.read(), output_format='html4')
pdfkit.from_string(html_text, output_filename)
# return http status code 204 from a django view
return HttpResponse(status=204)
# assign an array of floats in range from 0 to 100 to a variable `values`
values = np.array([i for i in range(100)], dtype=np.float64)
# create a NumPy array containing elements of array `A` as pointed to by index in array `B`
A[np.arange(A.shape[0])[:, (None)], B]
# remove adjacent duplicate elements from a list `[1, 2, 2, 3, 2, 2, 4]`
[k for k, g in itertools.groupby([1, 2, 2, 3, 2, 2, 4])]
# set labels `[1, 2, 3, 4, 5]` on axis X in plot `plt`
plt.xticks([1, 2, 3, 4, 5])
# get value of the environment variable 'KEY_THAT_MIGHT_EXIST'
print(os.environ.get('KEY_THAT_MIGHT_EXIST'))
# get value of the environment variable 'HOME' with default value '/home/username/'
print(os.environ.get('HOME', '/home/username/'))
# find all the indexes in a Numpy 2D array where the value is 1
zip(*np.where(a == 1))
# How to find the index of a value in 2d array in Python?
np.where(a == 1)
# split dictionary/list inside a pandas column 'b' into separate columns in dataframe `df`
pd.concat([df.drop('b', axis=1), pd.DataFrame(df['b'].tolist())], axis=1)
# reorder indexed rows `['Z', 'C', 'A']` based on a list in pandas data frame `df`
df.reindex(['Z', 'C', 'A'])
# store the output of command 'ls' in variable `direct_output`
direct_output = subprocess.check_output('ls', shell=True)
# reverse all x-axis points in pyplot
plt.gca().invert_xaxis()
# Iterate over dictionary `d` in ascending order of values
sorted(iter(d.items()), key=lambda x: x[1])
# read file 'myfile.txt' using universal newline mode 'U'
print(open('myfile.txt', 'U').read())
# Change the mode of file 'my_script.sh' to permission number 484
os.chmod('my_script.sh', 484)
# multiply array `a` and array `b`respective elements then sum each row of the new array
np.einsum('ji,i->j', a, b)
# execute sql query 'INSERT INTO table VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)' with all parameters in list `tup`
cur.executemany('INSERT INTO table VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)', tup)
# lowercase string values with key 'content' in a list of dictionaries `messages`
[{'content': x['content'].lower()} for x in messages]
# Unpack column 'stats' in dataframe `df` into a series of columns
df['stats'].apply(pd.Series)
# lookup an attribute in any scope by name 'range'
getattr(__builtins__, 'range')
# Remove character `char` from a string `a`
a = a.replace(char, '')
# Remove characters in `b` from a string `a`
a = a.replace(char, '')
# SQLAlchemy count the number of rows in table `Congress`
rows = session.query(Congress).count()
# find the index of the second occurrence of the substring `bar` in string `foo bar bar bar`
"""foo bar bar bar""".replace('bar', 'XXX', 1).find('bar')
# concatenate a series `students` onto a dataframe `marks` with pandas
pd.concat([students, pd.DataFrame(marks)], axis=1)
# create list `randomList` with 10 random floating point numbers between 0.0 and 1.0
randomList = [random.random() for _ in range(10)]
# create dictionary from list of variables 'foo' and 'bar' already defined
dict((k, globals()[k]) for k in ('foo', 'bar'))
# get a dataframe `df2` that contains all the columns of dataframe `df` that do not end in `prefix`
df2 = df.ix[:, (~df.columns.str.endswith('prefix'))]
# substract 1 hour and 10 minutes from current time
t = datetime.datetime.now()
(t - datetime.timedelta(hours=1, minutes=10))
# add 1 hour and 2 minutes to time object `t`
dt = datetime.datetime.combine(datetime.date.today(), t)
# Create new string with unique characters from `s` seperated by ' '
print(' '.join(OrderedDict.fromkeys(s)))
# create a set from string `s` to remove duplicate characters
print(' '.join(set(s)))
# find the index of the maximum value in the array `arr` where the boolean condition in array `cond` is true
np.ma.array(np.tile(arr, 2).reshape(2, 3), mask=~cond).argmax(axis=1)
# Get data from matplotlib plot
gca().get_lines()[n].get_xydata()
# BeautifulSoup search string 'Elsie' inside tag 'a'
soup.find_all('a', string='Elsie')
# create a dataframe containing the multiplication of element-wise in dataframe `df` and dataframe `df2` using index name and column labels of dataframe `df`
pd.DataFrame(df.values * df2.values, columns=df.columns, index=df.index)
# sort a list of dictionaries `list_of_dct` by values in an order `order`
sorted(list_of_dct, key=lambda x: order.index(list(x.values())[0]))
# concatenate dataframe `df1` with `df2` whilst removing duplicates
pandas.concat([df1, df2]).drop_duplicates().reset_index(drop=True)
# pretty-print ordered dictionary `o`
pprint(dict(list(o.items())))
# import a nested module `c.py` within `b` within `a` with importlib
importlib.import_module('.c', 'a.b')
# import a module 'a.b.c' with importlib.import_module in python 2
importlib.import_module('a.b.c')
# update fields in Django model `Book` with arguments in dictionary `d` where primary key is equal to `pk`
Book.objects.filter(pk=pk).update(**d)
# update the fields in django model `Book` using dictionary `d`
Book.objects.create(**d)
# Generate MD5 checksum of file in the path `full_path` in hashlib
print(hashlib.md5(open(full_path, 'rb').read()).hexdigest())
# Get the number of NaN values in each column of dataframe `df`
df.isnull().sum()
# find all anchor tags in html `soup` whose url begins with `http://www.iwashere.com`
soup.find_all('a', href=re.compile('http://www\\.iwashere\\.com/'))
# find all anchors with a hyperlink that matches the pattern '^(?!(?:[a-zA-Z][a-zA-Z0-9+.-]*:|//))'
soup.find_all('a', href=re.compile('^(?!(?:[a-zA-Z][a-zA-Z0-9+.-]*:|//))'))
# generate a random 12-digit number
int(''.join(str(random.randint(0, 9)) for _ in range(12)))
# generate a random 12-digit number
"""""".join(str(random.randint(0, 9)) for _ in range(12))
# How to delete a record in Django models?
SomeModel.objects.filter(id=id).delete()
# retrieve all items in an numpy array 'x' except the item of the index 1
x[(np.arange(x.shape[0]) != 1), :, :]
# split dataframe `df` where the value of column `a` is equal to 'B'
df.groupby((df.a == 'B').shift(1).fillna(0).cumsum())
# removing control characters from a string `s`
return ''.join(ch for ch in s if unicodedata.category(ch)[0] != 'C')
# return a DateTime object with the current UTC date
today = datetime.datetime.utcnow().date()
# Parsing HTML string `html` using BeautifulSoup
parsed_html = BeautifulSoup(html)
print(parsed_html.body.find('div', attrs={'class': 'container', }).text)
# convert a column of list in series `s` to dummies
pd.get_dummies(s.apply(pd.Series).stack()).sum(level=0)
# create a matrix from a list `[1, 2, 3]`
x = scipy.matrix([1, 2, 3]).transpose()
# convert radians 1 to degrees
math.cos(math.radians(1))
# create an empty data frame `df2` with index from another data frame `df1`
df2 = pd.DataFrame(index=df1.index)
# make a window `root` jump to the front
root.attributes('-topmost', True)
# apply function `log2` to the grouped values by 'type' in dataframe `df`
df.groupby('type').apply(lambda x: np.mean(np.log2(x['v'])))
# print number 1255000 as thousands separators
locale.setlocale(locale.LC_ALL, 'en_US')
locale.format('%d', 1255000, grouping=True)
# Filter a json from a key-value pair as `{'fixed_key_1': 'foo2'}` in Django
Test.objects.filter(actions__contains=[{'fixed_key_1': 'foo2'}])
# Move x-axis of the pyplot object `ax` to the top of a plot in matplotlib
ax.xaxis.set_ticks_position('top')
# check if date `yourdatetime` is equal to today's date
yourdatetime.date() == datetime.today().date()
# disable the certificate check in https requests for url `https://kennethreitz.com`
requests.get('https://kennethreitz.com', verify=False)
# create a list containing all cartesian products of elements in list `a`
list(itertools.product(*a))
# generate a random string of length `x`  containing lower cased ASCII letters
"""""".join(random.choice(string.lowercase) for x in range(X))
# get UTC datetime in ISO format
datetime.datetime.utcnow().isoformat()
# Keep only unique words in list of words `words` and join into string
print(' '.join(sorted(set(words), key=words.index)))
# convert a number 2130706433 to ip string
socket.inet_ntoa(struct.pack('!L', 2130706433))
# numpy:  check if array 'a' contains all the numbers in array 'b'.
numpy.array([(x in a) for x in b])
# Write column 'sum' of DataFrame `a` to csv file 'test.csv'
a.to_csv('test.csv', cols=['sum'])
# filter dataframe `grouped` where the length of each group `x` is bigger than 1
grouped.filter(lambda x: len(x) > 1)
# set the y axis range to `0, 1000` in subplot using pylab
pylab.ylim([0, 1000])
# get yesterday's date as a string in `YYYY-MM-DD` format using timedelta
(datetime.now() - timedelta(1)).strftime('%Y-%m-%d')
# Display a image file `pathToFile`
Image.open('pathToFile').show()
# convert decimal `8` to binary list
[int(x) for x in bin(8)[2:]]
# Rename a folder `Joe Blow` to `Blow, Joe`
os.rename('Joe Blow', 'Blow, Joe')
# create a 2D array of `Node` objects with dimensions `cols` columns and `rows` rows
nodes = [[Node() for j in range(cols)] for i in range(rows)]
# get the indexes of the x and y axes in Numpy array `np` where variable `a` is equal to variable `value`
i, j = np.where(a == value)
# Convert a binary value '1633837924' to string
struct.pack('<I', 1633837924)
# get rows of dataframe `df` where column `Col1` has values `['men', 'rocks', 'mountains']`
df[df.Col1.isin(['men', 'rocks', 'mountains'])]
# print current date and time in a regular format
datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
# How do I create a LIST of unique random numbers?
random.sample(list(range(100)), 10)
# find the index of element closest to number 11.5 in list `a`
min(enumerate(a), key=lambda x: abs(x[1] - 11.5))
# create 4 numbers in range between 1 and 3
print(np.linspace(1, 3, num=4, endpoint=False))
# Create numpy array of `5` numbers starting from `1` with interval of `3`
print(np.linspace(1, 3, num=5))
# split list `mylist` into a list of lists whose elements have the same first five characters
[list(v) for k, v in itertools.groupby(mylist, key=lambda x: x[:5])]
# find the minimum value in a numpy array `arr` excluding 0
arr[arr != 0].min()
# access an arbitrary value from dictionary `dict`
next(iter(list(dict.values())))
# Get a list values of a dictionary item `pass_id` from post requests in django
request.POST.getlist('pass_id')
# get number in list `myList` closest in value to number `myNumber`
min(myList, key=lambda x: abs(x - myNumber))
# Concat each values in a tuple `(34.2424, -64.2344, 76.3534, 45.2344)` to get a string
"""""".join(str(i) for i in (34.2424, -64.2344, 76.3534, 45.2344))
# run the code contained in string "print('Hello')"
eval("print('Hello')")
# convert bytes string `s`  to an unsigned integer
struct.unpack('>q', s)[0]
# Get a random string of length `length`
return ''.join(random.choice(string.lowercase) for i in range(length))
# access the class variable `a_string` from a class object `test`
getattr(test, a_string)
# disable abbreviation in argparse
parser = argparse.ArgumentParser(allow_abbrev=False)
# get a dictionary in list `dicts` which key 'ratio' is closer to a global value 1.77672955975
min(dicts, key=lambda x: (abs(1.77672955975 - x['ratio']), -x['pixels']))
# copy the content of file 'file.txt' to file 'file2.txt'
shutil.copy('file.txt', 'file2.txt')
# Calling an external command "echo Hello World"
print(subprocess.Popen('echo Hello World', shell=True, stdout=subprocess.PIPE).stdout.read())
# Calling an external command "echo Hello World"
print(os.popen('echo Hello World').read())
# Calling an external command "ls"
p = subprocess.Popen('ls', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
    print(line, end=' ')
retval = p.wait()
# convert numpy array into python list structure
np.array([[1, 2, 3], [4, 5, 6]]).tolist()
# rename file `dir` to `dir` + '!'
os.rename(dir, dir + '!')
# use operations like max/min within a row to a dataframe 'd' in pandas
d.apply(lambda row: min([row['A'], row['B']]) - row['C'], axis=1)
# How to plot with x-axis at the top of the figure?
ax.xaxis.set_ticks_position('top')
# sum the column `positions` along the  other columns `stock`, `same1`, `same2` in a pandas data frame `df`
df.groupby(['stock', 'same1', 'same2'], as_index=False)['positions'].sum()
# Summing across rows of Pandas Dataframe
df.groupby(['stock', 'same1', 'same2'])['positions'].sum().reset_index()