question_id
stringlengths
7
12
nl
stringlengths
4
200
cmd
stringlengths
2
232
oracle_man
sequence
canonical_cmd
stringlengths
2
228
cmd_name
stringclasses
1 value
7741878-15
apply `numpy.linalg.norm` to each row of a matrix `a`
numpy.apply_along_axis(numpy.linalg.norm, 1, a)
[ "numpy.reference.generated.numpy.apply_along_axis" ]
numpy.apply_along_axis(numpy.linalg.norm, 1, VAR_STR)
conala
10895028-20
append dict `{'f': var6, 'g': var7, 'h': var8}` to value of key `e` in dict `jsobj['a']['b']`
jsobj['a']['b']['e'].append({'f': var6, 'g': var7, 'h': var8})
[ "numpy.reference.generated.numpy.append" ]
jsobj['a']['b']['VAR_STR'].append({VAR_STR})
conala
21104592-91
read json `elevations` to pandas dataframe `df`
pd.read_json(elevations)
[ "pandas.reference.api.pandas.read_json" ]
pd.read_json(VAR_STR)
conala
12324456-53
keep a list `dataList` of lists sorted as it is created by second element
dataList.sort(key=lambda x: x[1])
[ "python.library.stdtypes#list.sort" ]
VAR_STR.sort(key=lambda x: x[1])
conala
10213994-42
sorting a list of tuples `list_of_tuples` where each tuple is reversed
sorted(list_of_tuples, key=lambda tup: tup[::-1])
[ "python.library.functions#sorted" ]
sorted(VAR_STR, key=lambda tup: tup[::-1])
conala
10213994-17
sorting a list of tuples `list_of_tuples` by second key
sorted(list_of_tuples, key=lambda tup: tup[1])
[ "python.library.functions#sorted" ]
sorted(VAR_STR, key=lambda tup: tup[1])
conala
5251663-9
check if any values in a list `input_list` is a list
any(isinstance(el, list) for el in input_list)
[ "python.library.functions#isinstance", "python.library.functions#any" ]
any(isinstance(el, list) for el in VAR_STR)
conala
4877844-81
check if string 'x' is in list `['x', 'd', 'a', 's', 'd', 's']`
'x' in ['x', 'd', 'a', 's', 'd', 's']
[]
'VAR_STR' in ['VAR_STR', 'd', 'a', 's', 'd', 's']
conala
40016359-9
Get the first and last 3 elements of list `l`
l[:3] + l[-3:]
[]
VAR_STR[:3] + VAR_STR[-3:]
conala
1038824-12
remove a substring ".com" from the end of string `url`
if url.endswith('.com'): url = url[:(-4)]
[ "python.library.stdtypes#str.endswith" ]
if VAR_STR.endswith('VAR_STR'): VAR_STR = VAR_STR[:-4]
conala
1038824-99
remove a substring ".com" from the end of string `url`
url = re.sub('\\.com$', '', url)
[ "python.library.re#re.sub" ]
VAR_STR = re.sub('\\.com$', '', VAR_STR)
conala
1038824-76
remove a substring ".com" from the end of string `url`
print(url.replace('.com', ''))
[ "python.library.stdtypes#str.replace" ]
print(VAR_STR.replace('VAR_STR', ''))
conala
1038824-70
remove a substring `suffix` from the end of string `text`
if (not text.endswith(suffix)): return text return text[:(len(text) - len(suffix))]
[ "python.library.functions#len" ]
if not VAR_STR.endswith(VAR_STR): return VAR_STR return VAR_STR[:len(VAR_STR) - len(VAR_STR)]
conala
40319433-71
find the euclidean distance between two 3-d arrays `A` and `B`
np.sqrt(((A - B) ** 2).sum(-1))
[ "numpy.reference.generated.numpy.sqrt", "python.library.functions#sum" ]
np.sqrt(((VAR_STR - VAR_STR) ** 2).sum(-1))
conala
2094176-57
split string `a` using new-line character '\n' as separator
a.rstrip().split('\n')
[ "python.library.stdtypes#str.rstrip", "python.library.stdtypes#str.split" ]
VAR_STR.rstrip().split('VAR_STR')
conala
2094176-44
split a string `a` with new line character
a.split('\n')[:-1]
[ "python.library.stdtypes#str.split" ]
VAR_STR.split('\n')[:-1]
conala
4979542-63
unpack the arguments out of list `params` to function `some_func`
some_func(*params)
[]
VAR_STR(*VAR_STR)
conala
8383213-96
python regex for hyphenated words in `text`
re.findall('\\w+(?:-\\w+)+', text)
[ "python.library.re#re.findall" ]
re.findall('\\w+(?:-\\w+)+', VAR_STR)
conala
31029560-17
plot a bar graph from the column 'color' in the DataFrame 'df'
df.colour.value_counts().plot(kind='bar')
[ "pandas.reference.api.pandas.dataframe.value_counts", "pandas.reference.api.pandas.dataframe.plot" ]
VAR_STR.colour.value_counts().plot(kind='bar')
conala
31029560-68
plot categorical data in series `df` with kind `bar` using pandas and matplotlib
df.groupby('colour').size().plot(kind='bar')
[ "pandas.reference.api.pandas.dataframe.groupby", "pandas.reference.api.pandas.dataframe.plot", "pandas.reference.api.pandas.dataframe.size" ]
VAR_STR.groupby('colour').size().plot(kind='VAR_STR')
conala
18319101-1
generate random upper-case ascii string of 12 characters length
print(''.join(choice(ascii_uppercase) for i in range(12)))
[ "python.library.functions#range", "python.library.random#random.choice", "python.library.stdtypes#str.join" ]
print(''.join(choice(ascii_uppercase) for i in range(12)))
conala
7934620-36
python: dots in the name of variable in a format string
"""Name: {0[person.name]}""".format({'person.name': 'Joe'})
[ "python.library.functions#format" ]
"""Name: {0[person.name]}""".format({'person.name': 'Joe'})
conala
13954840-33
open the file 'words.txt' in 'rU' mode
f = open('words.txt', 'rU')
[ "python.library.urllib.request#open" ]
f = open('VAR_STR', 'VAR_STR')
conala
39602824-29
Replace each value in column 'prod_type' of dataframe `df` with string 'responsive'
df['prod_type'] = 'responsive'
[]
VAR_STR['VAR_STR'] = 'VAR_STR'
conala
16994696-65
python get time stamp on file `file` in '%m/%d/%Y' format
time.strftime('%m/%d/%Y', time.gmtime(os.path.getmtime(file)))
[ "python.library.time#time.gmtime", "python.library.time#time.strftime", "python.library.os.path#os.path.getmtime" ]
time.strftime('VAR_STR', time.gmtime(os.path.getmtime(VAR_STR)))
conala
23887881-8
duplicate data in pandas dataframe `x` for 5 times
pd.concat([x] * 5, ignore_index=True)
[ "pandas.reference.api.pandas.concat" ]
pd.concat([VAR_STR] * 5, ignore_index=True)
conala
23887881-70
Get a repeated pandas data frame object `x` by `5` times
pd.concat([x] * 5)
[ "pandas.reference.api.pandas.concat" ]
pd.concat([VAR_STR] * 5)
conala
6278847-2
kill a process `make.exe` from python script on windows
os.system('taskkill /im make.exe')
[ "python.library.os#os.system" ]
os.system('taskkill /im make.exe')
conala
22240602-20
check if all elements in list `mylist` are the same
len(set(mylist)) == 1
[ "python.library.functions#len", "python.library.stdtypes#set" ]
len(set(VAR_STR)) == 1
conala
8209568-32
draw a grid line on every tick of plot `plt`
plt.grid(True)
[ "matplotlib._as_gen.mpl_toolkits.axisartist.axislines.axes#mpl_toolkits.axisartist.axislines.Axes.grid" ]
VAR_STR.grid(True)
conala
11303238-52
find recurring patterns in a string '42344343434'
re.findall('^(.+?)((.+)\\3+)$', '42344343434')[0][:-1]
[ "python.library.re#re.findall" ]
re.findall('^(.+?)((.+)\\3+)$', 'VAR_STR')[0][:-1]
conala
6294179-66
How to find all occurrences of an element in a list?
indices = [i for i, x in enumerate(my_list) if x == 'whatever']
[ "python.library.functions#enumerate" ]
indices = [i for i, x in enumerate(my_list) if x == 'whatever']
conala
15183084-19
create a dictionary using two lists`x` and `y`
dict(zip(x, y))
[ "python.library.functions#zip", "python.library.stdtypes#dict" ]
dict(zip(VAR_STR, VAR_STR))
conala
3430372-86
get full path of current directory
os.path.dirname(os.path.abspath(__file__))
[ "python.library.os.path#os.path.dirname", "python.library.os.path#os.path.abspath" ]
os.path.dirname(os.path.abspath(__file__))
conala
11811392-43
generate a list from a pandas dataframe `df` with the column name and column values
df.values.tolist()
[ "pandas.reference.api.pandas.series.tolist" ]
VAR_STR.values.tolist()
conala
12310141-33
check if all lists in list `L` have three elements of integer 1
all(x.count(1) == 3 for x in L)
[ "python.library.functions#all", "python.library.stdtypes#str.count" ]
all(x.count(1) == 3 for x in VAR_STR)
conala
5048841-98
Sort list `my_list` in alphabetical order based on the values associated with key 'name' of each dictionary in the list
my_list.sort(key=operator.itemgetter('name'))
[ "python.library.operator#operator.itemgetter", "python.library.stdtypes#list.sort" ]
VAR_STR.sort(key=operator.itemgetter('VAR_STR'))
conala
24076297-68
display first 5 characters of string 'aaabbbccc'
"""{:.5}""".format('aaabbbccc')
[ "python.library.functions#format" ]
"""{:.5}""".format('VAR_STR')
conala
16374540-19
Convert a list `['A:1', 'B:2', 'C:3', 'D:4']` to dictionary
dict(map(lambda s: s.split(':'), ['A:1', 'B:2', 'C:3', 'D:4']))
[ "python.library.functions#map", "python.library.stdtypes#dict", "python.library.stdtypes#str.split" ]
dict(map(lambda s: s.split(':'), [VAR_STR]))
conala
13571134-46
recursively go through all subdirectories and files in `rootdir`
for (root, subFolders, files) in os.walk(rootdir): pass
[ "python.library.os#os.walk" ]
for root, subFolders, files in os.walk(VAR_STR): pass
conala
6618515-54
sort list `X` based on values from another list `Y`
[x for y, x in sorted(zip(Y, X))]
[ "python.library.functions#zip", "python.library.functions#sorted" ]
[x for y, x in sorted(zip(VAR_STR, VAR_STR))]
conala
6618515-6
sorting list 'X' based on values from another list 'Y'
[x for y, x in sorted(zip(Y, X))]
[ "python.library.functions#zip", "python.library.functions#sorted" ]
[x for y, x in sorted(zip(VAR_STR, VAR_STR))]
conala
640001-87
remove parentheses and text within it in string `filename`
re.sub('\\([^)]*\\)', '', filename)
[ "python.library.re#re.sub" ]
re.sub('\\([^)]*\\)', '', VAR_STR)
conala
14853243-64
find all `owl:Class` tags by parsing xml with namespace
root.findall('{http://www.w3.org/2002/07/owl#}Class')
[ "python.library.re#re.findall" ]
root.findall('{http://www.w3.org/2002/07/owl#}Class')
conala
6740865-68
print a unicode string `text`
print(text.encode('windows-1252'))
[ "python.library.stdtypes#str.encode" ]
print(VAR_STR.encode('windows-1252'))
conala
41192805-11
Concatenate dataframe `df_1` to dataframe `df_2` sorted by values of the column 'y'
pd.concat([df_1, df_2.sort_values('y')])
[ "pandas.reference.api.pandas.concat", "pandas.reference.api.pandas.dataframe.sort_values" ]
pd.concat([VAR_STR, VAR_STR.sort_values('VAR_STR')])
conala
15014276-86
sum values greater than 0 in dictionary `d`
sum(v for v in list(d.values()) if v > 0)
[ "python.library.functions#sum", "python.library.functions#list", "python.library.stdtypes#dict.values" ]
sum(v for v in list(VAR_STR.values()) if v > 0)
conala
18131367-54
Get all the items from a list of tuple 'l' where second item in tuple is '1'.
[x for x in l if x[1] == 1]
[]
[x for x in VAR_STR if x[1] == 1]
conala
12030074-25
generate list of numbers in specific format using string formatting precision.
[('%.2d' % i) for i in range(16)]
[ "python.library.functions#range" ]
[('%.2d' % i) for i in range(16)]
conala
41133414-48
strip everything up to and including the character `&` from url `url`, strip the character `=` from the remaining string and concatenate `.html` to the end
url.split('&')[-1].replace('=', '') + '.html'
[ "python.library.stdtypes#str.replace", "python.library.stdtypes#str.split" ]
VAR_STR.split('VAR_STR')[-1].replace('VAR_STR', '') + 'VAR_STR'
conala
1058712-18
select a random element from array `[1, 2, 3]`
random.choice([1, 2, 3])
[ "python.library.random#random.choice" ]
random.choice([VAR_STR])
conala
22520932-13
remove all non-alphabet chars from string `s`
"""""".join([i for i in s if i.isalpha()])
[ "python.library.stdtypes#str.isalpha", "python.library.stdtypes#str.join" ]
"""""".join([i for i in VAR_STR if i.isalpha()])
conala
23797491-57
convert date strings in pandas dataframe column`df['date']` to pandas timestamps using the format '%d%b%Y'
df['date'] = pd.to_datetime(df['date'], format='%d%b%Y')
[ "pandas.reference.api.pandas.to_datetime" ]
df['date'] = pd.to_datetime(df['date'], format='VAR_STR')
conala
21822054-79
force bash interpreter '/bin/bash' to be used instead of shell
os.system('GREPDB="echo 123"; /bin/bash -c "$GREPDB"')
[ "python.library.os#os.system" ]
os.system('GREPDB="echo 123"; /bin/bash -c "$GREPDB"')
conala
21822054-28
Run a command `echo hello world` in bash instead of shell
os.system('/bin/bash -c "echo hello world"')
[ "python.library.os#os.system" ]
os.system('/bin/bash -c "echo hello world"')
conala
18358938-63
get index values of pandas dataframe `df` as list
df.index.values.tolist()
[ "pandas.reference.api.pandas.index.tolist" ]
VAR_STR.index.values.tolist()
conala
30241279-15
run app `app` on host '192.168.0.58' and port 9000 in Flask
app.run(host='192.168.0.58', port=9000, debug=False)
[ "python.library.pdb#pdb.run" ]
VAR_STR.run(host='VAR_STR', port=9000, debug=False)
conala
727507-53
print unicode string `ex\xe1mple` in uppercase
print('ex\xe1mple'.upper())
[ "python.library.stdtypes#str.upper" ]
print('VAR_STR'.upper())
conala
40639071-13
Get the sum of values to the power of their indices in a list `l`
sum(j ** i for i, j in enumerate(l, 1))
[ "python.library.functions#enumerate", "python.library.functions#sum" ]
sum(j ** i for i, j in enumerate(VAR_STR, 1))
conala
14162026-97
get the first row, second column; second row, first column, and first row third column values of numpy array `arr`
arr[[0, 1, 1], [1, 0, 2]]
[]
VAR_STR[[0, 1, 1], [1, 0, 2]]
conala
28538536-94
Delete mulitple columns `columnheading1`, `columnheading2` in pandas data frame `yourdf`
yourdf.drop(['columnheading1', 'columnheading2'], axis=1, inplace=True)
[ "pandas.reference.api.pandas.dataframe.drop" ]
VAR_STR.drop(['VAR_STR', 'VAR_STR'], axis=1, inplace=True)
conala
40079728-79
Django get first 10 records of model `User` ordered by criteria 'age' of model 'pet'
User.objects.order_by('-pet__age')[:10]
[]
VAR_STR.objects.order_by('-pet__age')[:10]
conala
8924173-17
print bold text 'Hello'
print('\x1b[1m' + 'Hello')
[]
print('\x1b[1m' + 'VAR_STR')
conala
3781851-15
run python script 'script2.py' from another python script, passing in 1 as an argument
os.system('script2.py 1')
[ "python.library.os#os.system" ]
os.system('script2.py 1')
conala
18504967-17
create new column `A_perc` in dataframe `df` with row values equal to the value in column `A` divided by the value in column `sum`
df['A_perc'] = df['A'] / df['sum']
[]
VAR_STR['VAR_STR'] = VAR_STR['VAR_STR'] / VAR_STR['VAR_STR']
conala
11697709-100
list duplicated elements in two lists `listA` and `listB`
list(set(listA) & set(listB))
[ "python.library.stdtypes#set", "python.library.functions#list" ]
list(set(VAR_STR) & set(VAR_STR))
conala
10365225-64
extract digits in a simple way from a python string
map(int, re.findall('\\d+', s))
[ "python.library.re#re.findall", "python.library.functions#map" ]
map(int, re.findall('\\d+', s))
conala
11430863-98
find overlapping matches from a string `hello` using regex
re.findall('(?=(\\w\\w))', 'hello')
[ "python.library.re#re.findall" ]
re.findall('(?=(\\w\\w))', 'VAR_STR')
conala
25991612-67
Python / Remove special character from string
re.sub('[^a-zA-Z0-9-_*.]', '', my_string)
[ "python.library.re#re.sub" ]
re.sub('[^a-zA-Z0-9-_*.]', '', my_string)
conala
2597099-85
Sort list `keys` based on its elements' dot-seperated numbers
keys.sort(key=lambda x: map(int, x.split('.')))
[ "python.library.functions#map", "python.library.stdtypes#list.sort", "python.library.stdtypes#str.split" ]
VAR_STR.sort(key=lambda x: map(int, x.split('.')))
conala
2597099-42
Sort a list of integers `keys` where each value is in string format
keys.sort(key=lambda x: [int(y) for y in x.split('.')])
[ "python.library.functions#int", "python.library.stdtypes#list.sort", "python.library.stdtypes#str.split" ]
VAR_STR.sort(key=lambda x: [int(y) for y in x.split('.')])
conala
1874194-65
get the tuple in list `a_list` that has the largest item in the second index
max_item = max(a_list, key=operator.itemgetter(1))
[ "python.library.operator#operator.itemgetter", "python.library.functions#max" ]
max_item = max(VAR_STR, key=operator.itemgetter(1))
conala
1874194-25
find tuple in list of tuples `a_list` with the largest second element
max(a_list, key=operator.itemgetter(1))
[ "python.library.operator#operator.itemgetter", "python.library.functions#max" ]
max(VAR_STR, key=operator.itemgetter(1))
conala
16196712-48
wait for shell command `p` evoked by subprocess.Popen to complete
p.wait()
[ "python.library.os#os.wait" ]
VAR_STR.wait()
conala
42462530-4
replace white spaces in dataframe `df` with '_'
df.replace(' ', '_', regex=True)
[ "pandas.reference.api.pandas.dataframe.replace" ]
VAR_STR.replace(' ', 'VAR_STR', regex=True)
conala
30628176-5
switch positions of each two adjacent characters in string `a`
print(''.join(''.join(i) for i in zip(a2, a1)) + a[-1] if len(a) % 2 else '')
[ "python.library.functions#zip", "python.library.functions#len", "python.library.stdtypes#str.join" ]
print(''.join(''.join(i) for i in zip(a2, a1)) + VAR_STR[-1] if len(VAR_STR) % 2 else '')
conala
4289331-11
Python: Extract numbers from a string
[int(s) for s in re.findall('\\b\\d+\\b', "he33llo 42 I'm a 32 string 30")]
[ "python.library.re#re.findall", "python.library.functions#int" ]
[int(s) for s in re.findall('\\b\\d+\\b', "he33llo 42 I'm a 32 string 30")]
conala
4241757-59
remove extra white spaces & tabs from a string `s`
""" """.join(s.split())
[ "python.library.stdtypes#str.join", "python.library.stdtypes#str.split" ]
""" """.join(VAR_STR.split())
conala
4810537-49
clear terminal screen on windows
os.system('cls')
[ "python.library.os#os.system" ]
os.system('cls')
conala
4810537-55
clear the terminal screen in Linux
os.system('clear')
[ "python.library.os#os.system" ]
os.system('clear')
conala
23306653-53
get value of key `post code` associated with first index of key `places` of dictionary `data`
print(data['places'][0]['post code'])
[]
print(VAR_STR['VAR_STR'][0]['VAR_STR'])
conala
4111412-34
get a list of indices of non zero elements in a list `a`
[i for i, e in enumerate(a) if e != 0]
[ "python.library.functions#enumerate" ]
[i for i, e in enumerate(VAR_STR) if e != 0]
conala
17589590-99
Define a list with string values `['a', 'c', 'b', 'obj']`
['a', 'c', 'b', 'obj']
[]
[VAR_STR]
conala
38273353-74
repeat every character for 7 times in string 'map'
"""""".join(map(lambda x: x * 7, 'map'))
[ "python.library.functions#map", "python.library.stdtypes#str.join" ]
"""""".join(VAR_STR(lambda x: x * 7, 'VAR_STR'))
conala
817087-38
call a function with argument list `args`
func(*args)
[ "python.library.functools#functools.partial.func" ]
func(*VAR_STR)
conala
14764126-22
restart a computer after `900` seconds using subprocess
subprocess.call(['shutdown', '/r', '/t', '900'])
[ "python.library.subprocess#subprocess.call" ]
subprocess.call(['shutdown', '/r', '/t', 'VAR_STR'])
conala
14764126-20
shutdown a computer using subprocess
subprocess.call(['shutdown', '/s'])
[ "python.library.subprocess#subprocess.call" ]
subprocess.call(['shutdown', '/s'])
conala
14764126-37
abort a computer shutdown using subprocess
subprocess.call(['shutdown', '/a '])
[ "python.library.subprocess#subprocess.call" ]
subprocess.call(['shutdown', '/a '])
conala
14764126-39
logoff computer having windows operating system using python
subprocess.call(['shutdown', '/l '])
[ "python.library.subprocess#subprocess.call" ]
subprocess.call(['shutdown', '/l '])
conala
14764126-27
shutdown and restart a computer running windows from script
subprocess.call(['shutdown', '/r'])
[ "python.library.subprocess#subprocess.call" ]
subprocess.call(['shutdown', '/r'])
conala
6996603-67
delete an empty directory
os.rmdir()
[ "python.library.os#os.rmdir" ]
os.rmdir()
conala
6996603-65
recursively delete all contents in directory `path`
shutil.rmtree(path, ignore_errors=False, onerror=None)
[ "python.library.shutil#shutil.rmtree" ]
shutil.rmtree(VAR_STR, ignore_errors=False, onerror=None)
conala
6996603-99
recursively remove folder `name`
os.removedirs(name)
[ "python.library.os#os.removedirs" ]
os.removedirs(VAR_STR)
conala
18695605-99
convert pandas DataFrame `df` to a dictionary using `id` field as the key
df.set_index('id').to_dict()
[ "pandas.reference.api.pandas.dataframe.set_index", "pandas.reference.api.pandas.dataframe.to_dict" ]
VAR_STR.set_index('VAR_STR').to_dict()
conala
18695605-31
convert pandas dataframe `df` with fields 'id', 'value' to dictionary
df.set_index('id')['value'].to_dict()
[ "pandas.reference.api.pandas.dataframe.set_index", "pandas.reference.api.pandas.dataframe.to_dict" ]
VAR_STR.set_index('VAR_STR')['VAR_STR'].to_dict()
conala
8556076-78
create list `new_list` containing the last 10 elements of list `my_list`
new_list = my_list[-10:]
[]
VAR_STR = VAR_STR[-10:]
conala
8556076-43
get the last 10 elements from a list `my_list`
my_list[-10:]
[]
VAR_STR[-10:]
conala
33218968-14
Run 'test2.py' file with python location 'path/to/python' and arguments 'neededArgumetGoHere' as a subprocess
call(['path/to/python', 'test2.py', 'neededArgumetGoHere'])
[ "python.library.subprocess#subprocess.call" ]
call(['VAR_STR', 'VAR_STR', 'VAR_STR'])
conala
1101508-32
parse date string '2009/05/13 19:19:30 -0400' using format '%Y/%m/%d %H:%M:%S %z'
datetime.strptime('2009/05/13 19:19:30 -0400', '%Y/%m/%d %H:%M:%S %z')
[ "python.library.datetime#datetime.datetime.strptime" ]
datetime.strptime('VAR_STR', 'VAR_STR')
conala
34023918-59
make new column 'C' in panda dataframe by adding values from other columns 'A' and 'B'
df['C'] = df['A'] + df['B']
[]
df['VAR_STR'] = df['VAR_STR'] + df['VAR_STR']
conala