rewritten_intent
stringlengths 4
183
⌀ | intent
stringlengths 11
122
| snippet
stringlengths 2
232
| question_id
int64 1.48k
42.8M
|
---|---|---|---|
null | Clicking a link using selenium using python | driver.find_element_by_xpath('xpath').click() | 17,498,027 |
count unique index values in column 'A' in pandas dataframe `ex` | Counting unique index values in Pandas groupby | ex.groupby(level='A').agg(lambda x: x.index.get_level_values(1).nunique()) | 35,178,812 |
Create a pandas dataframe of values from a dictionary `d` which contains dictionaries of dictionaries | Dict of dicts of dicts to DataFrame | pd.concat(map(pd.DataFrame, iter(d.values())), keys=list(d.keys())).stack().unstack(0) | 15,455,388 |
find out the number of non-matched elements at the same index of list `a` and list `b` | In Python, find out number of differences between two ordered lists | sum(1 for i, j in zip(a, b) if i != j) | 14,914,615 |
make all keys lowercase in dictionary `d` | When the key is a tuple in dictionary in Python | d = {(a.lower(), b): v for (a, b), v in list(d.items())} | 21,833,383 |
sort list `list_` based on first element of each tuple and by the length of the second element of each tuple | Sorting a list of tuples with multiple conditions | list_.sort(key=lambda x: [x[0], len(x[1]), x[1]]) | 19,643,099 |
trim whitespace in string `s` | trim whitespace | s.strip() | 1,185,524 |
trim whitespace (including tabs) in `s` on the left side | trim whitespace (including tabs) | s = s.lstrip() | 1,185,524 |
trim whitespace (including tabs) in `s` on the right side | trim whitespace (including tabs) | s = s.rstrip() | 1,185,524 |
trim characters ' \t\n\r' in `s` | trim whitespace (including tabs) | s = s.strip(' \t\n\r') | 1,185,524 |
trim whitespaces (including tabs) in string `s` | trim whitespace (including tabs) | print(re.sub('[\\s+]', '', s)) | 1,185,524 |
In Django, filter `Task.objects` based on all entities in ['A', 'P', 'F'] | In Django, how do I filter based on all entities in a many-to-many relation instead of any? | Task.objects.exclude(prerequisites__status__in=['A', 'P', 'F']) | 1,516,795 |
Change background color in Tkinter | Background color for Tk in Python | root.configure(background='black') | 2,744,795 |
convert dict `result` to numpy structured array | python dict to numpy structured array | numpy.array([(key, val) for key, val in result.items()], dtype) | 15,579,649 |
Concatenate dataframe `df_1` to dataframe `df_2` sorted by values of the column 'y' | Pandas - Sorting By Column | pd.concat([df_1, df_2.sort_values('y')]) | 41,192,805 |
replace the last occurence of an expression '</div>' with '</bad>' in a string `s` | rreplace - How to replace the last occurence of an expression in a string? | re.sub('(.*)</div>', '\\1</bad>', s) | 2,556,108 |
get the maximum of 'salary' and 'bonus' values in a dictionary | How do I compare values in a dictionary? | print(max(d, key=lambda x: (d[x]['salary'], d[x]['bonus']))) | 42,211,584 |
Filter Django objects by `author` with ids `1` and `2` | How to do many-to-many Django query to find book with 2 given authors? | Book.objects.filter(author__id=1).filter(author__id=2) | 5,301,996 |
split string 'fooxyzbar' based on case-insensitive matching using string 'XYZ' | Python regex split case insensitive in 2.6 | re.compile('XYZ', re.IGNORECASE).split('fooxyzbar') | 8,993,904 |
get list of sums of neighboring integers in string `example` | List comprehension - converting strings in one list, to integers in another | [sum(map(int, s)) for s in example.split()] | 40,498,088 |
Get all the keys from dictionary `y` whose value is `1` | How to find duplicate elements in array using for loop in Python? | [i for i in y if y[i] == 1] | 1,920,145 |
converting byte string `c` in unicode string | Converting byte string in unicode string | c.decode('unicode_escape') | 13,837,848 |
unpivot first 2 columns into new columns 'year' and 'value' from a pandas dataframe `x` | How can I "unpivot" specific columns from a pandas DataFrame? | pd.melt(x, id_vars=['farm', 'fruit'], var_name='year', value_name='value') | 23,354,124 |
add key "item3" and value "3" to dictionary `default_data ` | add new item to dictionary | default_data['item3'] = 3 | 6,416,131 |
add key "item3" and value "3" to dictionary `default_data ` | add new item to dictionary | default_data.update({'item3': 3, }) | 6,416,131 |
add key value pairs 'item4' , 4 and 'item5' , 5 to dictionary `default_data` | add new item to dictionary | default_data.update({'item4': 4, 'item5': 5, }) | 6,416,131 |
Get the first and last 3 elements of list `l` | Index the first and the last n elements of a list | l[:3] + l[-3:] | 40,016,359 |
reset index to default in dataframe `df` | How to reset index in a pandas data frame? | df = df.reset_index(drop=True) | 20,490,274 |
For each index `x` from 0 to 3, append the element at index `x` of list `b` to the list at index `x` of list a. | Merging a list with a list of lists | [a[x].append(b[x]) for x in range(3)] | 18,872,717 |
get canonical path of the filename `path` | how to find the target file's full(absolute path) of the symbolic link or soft link in python | os.path.realpath(path) | 3,220,755 |
check if dictionary `L[0].f.items()` is in dictionary `a3.f.items()` | How to check if a dictionary is in another dictionary in python | set(L[0].f.items()).issubset(set(a3.f.items())) | 18,170,459 |
find all the indexes in a Numpy 2D array where the value is 1 | How to find the index of a value in 2d array in Python? | zip(*np.where(a == 1)) | 27,175,400 |
null | How to find the index of a value in 2d array in Python? | np.where(a == 1) | 27,175,400 |
Collapse hierarchical column index to level 0 in dataframe `df` | Python Pandas - How to flatten a hierarchical index in columns | df.columns = df.columns.get_level_values(0) | 14,507,794 |
create a matrix from a list `[1, 2, 3]` | Creating a list from a Scipy matrix | x = scipy.matrix([1, 2, 3]).transpose() | 4,690,366 |
add character '@' after word 'get' in string `text` | Regex Python adding characters after a certain word | text = re.sub('(\\bget\\b)', '\\1@', text) | 20,735,384 |
get a numpy array that contains the element wise minimum of three 3x1 arrays | Element-wise minimum of multiple vectors in numpy | np.array([np.arange(3), np.arange(2, -1, -1), np.ones((3,))]).min(axis=0) | 39,277,638 |
add a column 'new_col' to dataframe `df` for index in range | Pandas (python): How to add column to dataframe for index? | df['new_col'] = list(range(1, len(df) + 1)) | 12,168,648 |
set environment variable 'DEBUSSY' equal to 1 | How to set environment variables in Python | os.environ['DEBUSSY'] = '1' | 5,971,312 |
Get a environment variable `DEBUSSY` | How to set environment variables in Python | print(os.environ['DEBUSSY']) | 5,971,312 |
set environment variable 'DEBUSSY' to '1' | How to set environment variables in Python | os.environ['DEBUSSY'] = '1' | 5,971,312 |
update dictionary `b`, overwriting values where keys are identical, with contents of dictionary `d` | Python: updating a large dictionary using another large dictionary | b.update(d) | 12,717,716 |
get all the values in column `b` from pandas data frame `df` | How to get column by number in Pandas? | df['b'] | 17,193,850 |
make a line plot with errorbars, `ebar`, from data `x, y, err` and set color of the errorbars to `y` (yellow) | How can I get the color of the last figure in matplotlib? | ebar = plt.errorbar(x, y, yerr=err, ecolor='y') | 13,395,888 |
find all files with extension '.c' in directory `folder` | Python: How can I find all files with a particular extension? | results += [each for each in os.listdir(folder) if each.endswith('.c')] | 3,608,411 |
add unicode string '1' to UTF-8 decoded string '\xc2\xa3' | Concatenating Unicode with string: print '£' + '1' works, but print '£' + u'1' throws UnicodeDecodeError | print('\xc2\xa3'.decode('utf8') + '1') | 31,771,758 |
lower-case the string obtained by replacing the occurrences of regex pattern '(?<=[a-z])([A-Z])' in string `s` with eplacement '-\\1' | How to convert the following string in python? | re.sub('(?<=[a-z])([A-Z])', '-\\1', s).lower() | 39,414,085 |
null | Setting stacksize in a python script | os.system('ulimit -s unlimited; some_executable') | 5,061,582 |
format a string `num` using string formatting | Python Decimals format | """{0:.3g}""".format(num) | 2,389,846 |
append the first element of array `a` to array `a` | Add single element to array in numpy | numpy.append(a, a[0]) | 7,332,841 |
return the column for value 38.15 in dataframe `df` | Return the column name(s) for a specific value in a pandas dataframe | df.ix[:, (df.loc[0] == 38.15)].columns | 38,331,568 |
merge 2 dataframes `df1` and `df2` with same values in a column 'revenue' with and index 'date' | Merge 2 dataframes with same values in a column | df2['revenue'] = df2.CET.map(df1.set_index('date')['revenue']) | 41,463,763 |
load a json data `json_string` into variable `json_data` | How To Format a JSON Text In Python? | json_data = json.loads(json_string) | 23,970,693 |
convert radians 1 to degrees | Python: converting radians to degrees | math.cos(math.radians(1)) | 9,875,964 |
count the number of integers in list `a` | count how many of an object type there are in a list Python | sum(isinstance(x, int) for x in a) | 25,355,705 |
replacing '\u200b' with '*' in a string using regular expressions | Python: Getting rid of \u200b from a string using regular expressions | 'used\u200b'.replace('\u200b', '*') | 31,522,361 |
run function 'SudsMove' simultaneously | How to run two functions simultaneously | threading.Thread(target=SudsMove).start() | 2,108,126 |
sum of squares values in a list `l` | sum of squares in a list in one line? | sum(i * i for i in l) | 26,894,227 |
calculate the sum of the squares of each value in list `l` | sum of squares in a list in one line? | sum(map(lambda x: x * x, l)) | 26,894,227 |
Create a dictionary `d` from list `iterable` | Create a dictionary with list comprehension | d = dict(((key, value) for (key, value) in iterable)) | 1,747,817 |
Create a dictionary `d` from list `iterable` | Create a dictionary with list comprehension | d = {key: value for (key, value) in iterable} | 1,747,817 |
Create a dictionary `d` from list of key value pairs `iterable` | Create a dictionary with list comprehension | d = {k: v for (k, v) in iterable} | 1,747,817 |
round off entries in dataframe `df` column `Alabama_exp` to two decimal places, and entries in column `Credit_exp` to three decimal places | Rounding entries in a Pandas DafaFrame | df.round({'Alabama_exp': 2, 'Credit_exp': 3}) | 19,100,540 |
Make function `WRITEFUNCTION` output nothing in curl `p` | Pycurl keeps printing in terminal | p.setopt(pycurl.WRITEFUNCTION, lambda x: None) | 7,668,141 |
return a random word from a word list 'words' | Return a random word from a word list in python | print(random.choice(words)) | 1,456,617 |
Find a max value of the key `count` in a nested dictionary `d` | Find Max in Nested Dictionary | max(d, key=lambda x: d[x]['count']) | 12,829,889 |
get list of string elements in string `data` delimited by commas, putting `0` in place of empty strings | How to replace empty string with zero in comma-separated string? | [(int(x) if x else 0) for x in data.split(',')] | 2,606,976 |
split string `s` into a list of strings based on ',' then replace empty strings with zero | How to replace empty string with zero in comma-separated string? | """,""".join(x or '0' for x in s.split(',')) | 2,606,976 |
regular expression match nothing | Regular expression syntax for "match nothing"? | re.compile('$^') | 940,822 |
regular expression syntax for not to match anything | Regular expression syntax for "match nothing"? | re.compile('.\\A|.\\A*|.\\A+') | 940,822 |
create a regular expression object with a pattern that will match nothing | Regular expression syntax for "match nothing"? | re.compile('a^') | 940,822 |
drop all columns in dataframe `df` that holds a maximum value bigger than 0 | Python Pandas drop columns based on max value of column | df.columns[df.max() > 0] | 26,897,536 |
check if date `yourdatetime` is equal to today's date | How can I check if a date is the same day as datetime.today()? | yourdatetime.date() == datetime.today().date() | 6,407,362 |
print bold text 'Hello' | How do I print bold text in Python? | print('\x1b[1m' + 'Hello') | 8,924,173 |
remove 20 symbols in front of '.' in string 'unique12345678901234567890.mkv' | Renaming multiple files in python | re.sub('.{20}(.mkv)', '\\1', 'unique12345678901234567890.mkv') | 4,358,701 |
Define a list with string values `['a', 'c', 'b', 'obj']` | Can I get a list of the variables that reference an other in Python 2.7? | ['a', 'c', 'b', 'obj'] | 17,589,590 |
substitute multiple whitespace with single whitespace in string `mystring` | Substitute multiple whitespace with single whitespace in Python | """ """.join(mystring.split()) | 2,077,897 |
print a floating point number 2.345e-67 without any truncation | How to print floating point numbers as it is without any truncation in python? | print('{:.100f}'.format(2.345e-67)) | 20,048,987 |
Check if key 'key1' in `dict` | Check if a given key already exists in a dictionary | ('key1' in dict) | 1,602,934 |
Check if key 'a' in `d` | Check if a given key already exists in a dictionary | ('a' in d) | 1,602,934 |
Check if key 'c' in `d` | Check if a given key already exists in a dictionary | ('c' in d) | 1,602,934 |
Check if a given key 'key1' exists in dictionary `dict` | Check if a given key already exists in a dictionary | if ('key1' in dict):
pass | 1,602,934 |
Check if a given key `key` exists in dictionary `d` | Check if a given key already exists in a dictionary | if (key in d):
pass | 1,602,934 |
create a django query for a list of values `1, 4, 7` | django filter with list of values | Blog.objects.filter(pk__in=[1, 4, 7]) | 9,304,908 |
read a binary file 'test/test.pdf' | read a binary file (python) | f = open('test/test.pdf', 'rb') | 2,497,027 |
insert ' ' between every three digit before '.' and replace ',' with '.' in 12345678.46 | Format string - spaces between every three digit | format(12345678.46, ',').replace(',', ' ').replace('.', ',') | 17,484,631 |
Join pandas data frame `frame_1` and `frame_2` with left join by `county_ID` and right join by `countyid` | Joining pandas dataframes by column names | pd.merge(frame_1, frame_2, left_on='county_ID', right_on='countyid') | 20,375,561 |
calculate ratio of sparsity in a numpy array `a` | How to calculate percentage of sparsity for a numpy array/matrix? | np.isnan(a).sum() / np.prod(a.shape) | 38,708,621 |
reverse sort items in default dictionary `cityPopulation` by the third item in each key's list of values | Sorting a defaultdict by value in python | sorted(iter(cityPopulation.items()), key=lambda k_v: k_v[1][2], reverse=True) | 10,194,713 |
Sort dictionary `u` in ascending order based on second elements of its values | Sorting a defaultdict by value in python | sorted(list(u.items()), key=lambda v: v[1]) | 10,194,713 |
reverse sort dictionary `d` based on its values | Sorting a defaultdict by value in python | sorted(list(d.items()), key=lambda k_v: k_v[1], reverse=True) | 10,194,713 |
sorting a defaultdict `d` by value | Sorting a defaultdict by value in python | sorted(list(d.items()), key=lambda k_v: k_v[1]) | 10,194,713 |
open a file 'bundled-resource.jpg' in the same directory as a python script | How to reliably open a file in the same directory as a Python script | f = open(os.path.join(__location__, 'bundled-resource.jpg')) | 4,060,221 |
open the file 'words.txt' in 'rU' mode | How do I convert LF to CRLF? | f = open('words.txt', 'rU') | 13,954,840 |
divide the values with same keys of two dictionary `d1` and `d2` | Divide the values of two dictionaries in python | {k: (float(d2[k]) / d1[k]) for k in d2} | 11,840,111 |
divide the value for each key `k` in dict `d2` by the value for the same key `k` in dict `d1` | Divide the values of two dictionaries in python | {k: (d2[k] / d1[k]) for k in list(d1.keys()) & d2} | 11,840,111 |
divide values associated with each key in dictionary `d1` from values associated with the same key in dictionary `d2` | Divide the values of two dictionaries in python | dict((k, float(d2[k]) / d1[k]) for k in d2) | 11,840,111 |
write dataframe `df` to csv file `filename` with dates formatted as yearmonthday `%Y%m%d` | How to specify date format when using pandas.to_csv? | df.to_csv(filename, date_format='%Y%m%d') | 13,999,850 |
remove a key 'key' from a dictionary `my_dict` | How to remove a key from a python dictionary? | my_dict.pop('key', None) | 11,277,432 |
replace NaN values in array `a` with zeros | replace values in an array | b = np.where(np.isnan(a), 0, a) | 1,800,187 |