question_id
int64 1.48k
42.8M
| intent
stringlengths 11
122
| rewritten_intent
stringlengths 4
183
⌀ | snippet
stringlengths 2
232
|
---|---|---|---|
961,632 | Converting integer to string | convert `a` to string | str(a) |
5,201,191 | Method to sort a list of lists? | sort list of lists `L` by the second item in each list | L.sort(key=operator.itemgetter(1)) |
9,969,684 | How do I add space between two variables after a print in Python | Print variable `count` and variable `conv` with space string ' ' in between | print(str(count) + ' ' + str(conv)) |
38,457,059 | Pandas changing cell values based on another cell | change NaN values in dataframe `df` using preceding values in the frame | df.fillna(method='ffill', inplace=True) |
3,842,155 | Is there a way to make the Tkinter text widget read only? | change the state of the Tkinter `Text` widget to read only i.e. `disabled` | text.config(state=DISABLED) |
12,492,137 | Python sum of ASCII values of all characters in a string | python sum of ascii values of all characters in a string `string` | sum(map(ord, string)) |
3,034,014 | How to apply itertools.product to elements of a list of lists? | apply itertools.product to elements of a list of lists `arrays` | list(itertools.product(*arrays)) |
1,823,058 | print number with commas as thousands separators | print number `value` as thousands separators | '{:,}'.format(value) |
1,823,058 | print number with commas as thousands separators | print number 1255000 as thousands separators | locale.setlocale(locale.LC_ALL, 'en_US')
locale.format('%d', 1255000, grouping=True) |
39,988,589 | How to pass through a list of queries to a pandas dataframe, and output the list of results? | get rows of dataframe `df` where column `Col1` has values `['men', 'rocks', 'mountains']` | df[df.Col1.isin(['men', 'rocks', 'mountains'])] |
4,800,811 | Accessing a value in a tuple that is in a list | get the value at index 1 for each tuple in the list of tuples `L` | [x[1] for x in L] |
7,286,879 | splitting unicode string into words | split unicode string "раз два три" into words | '\u0440\u0430\u0437 \u0434\u0432\u0430 \u0442\u0440\u0438'.split() |
12,804,801 | Django - How to sort queryset by number of character in a field | sort query set by number of characters in a field `length` in django model `MyModel` | MyModel.objects.extra(select={'length': 'Length(name)'}).order_by('length') |
42,442,428 | Python - Choose a dictionary in list which key is closer to a global value | 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'])) |
3,262,437 | Finding missing values in a numpy array | get the non-masked values of array `m` | m[~m.mask] |
13,840,883 | Use of findall and parenthesis in Python | Find all words containing letters between A and Z in string `formula` | re.findall('\\b[A-Z]', formula) |
6,667,201 | How to define two-dimensional array in python | create a list `matrix` containing 5 lists, each of 5 items all set to 0 | matrix = [([0] * 5) for i in range(5)] |
18,253,210 | Creating a numpy array of 3D coordinates from three 1D arrays | creating a numpy array of 3d coordinates from three 1d arrays `x_p`, `y_p` and `z_p` | np.vstack(np.meshgrid(x_p, y_p, z_p)).reshape(3, -1).T |
11,764,260 | How to find the minimum value in a numpy matrix? | find the minimum value in a numpy array `arr` excluding 0 | arr[arr != 0].min() |
12,579,061 | Python Selenium: Find object attributes using xpath | get the text of multiple elements found by xpath "//*[@type='submit']/@value" | browser.find_elements_by_xpath("//*[@type='submit']/@value").text |
12,579,061 | Python Selenium: Find object attributes using xpath | find all the values in attribute `value` for the tags whose `type` attribute is `submit` in selenium | browser.find_elements_by_xpath("//*[@type='submit']").get_attribute('value') |
1,773,805 | parse a YAML file | parse a YAML file "example.yaml" | with open('example.yaml', 'r') as stream:
try:
print((yaml.load(stream)))
except yaml.YAMLError as exc:
print(exc) |
1,773,805 | parse a YAML file | parse a YAML file "example.yaml" | with open('example.yaml') as stream:
try:
print((yaml.load(stream)))
except yaml.YAMLError as exc:
print(exc) |
41,572,822 | How to swap a group of column headings with their values in Pandas | Sort the values of the dataframe `df` and align the columns accordingly based on the obtained indices after np.argsort. | pd.DataFrame(df.columns[np.argsort(df.values)], df.index, np.unique(df.values)) |
32,490,629 | Getting today's date in YYYY-MM-DD in Python? | Getting today's date in YYYY-MM-DD | datetime.datetime.today().strftime('%Y-%m-%d') |
5,607,551 | How to urlencode a querystring in Python? | urlencode a querystring 'string_of_characters_like_these:$#@=?%^Q^$' in python 2 | urllib.parse.quote_plus('string_of_characters_like_these:$#@=?%^Q^$') |
16,868,457 | python sorting dictionary by length of values | sort a dictionary `d` by length of its values and print as string | print(' '.join(sorted(d, key=lambda k: len(d[k]), reverse=True))) |
8,081,545 | convert list of tuples to multiple lists in Python | convert tuple elements in list `[(1,2),(3,4),(5,6),]` into lists | map(list, zip(*[(1, 2), (3, 4), (5, 6)])) |
8,081,545 | convert list of tuples to multiple lists in Python | null | map(list, zip(*[(1, 2), (3, 4), (5, 6)])) |
8,081,545 | convert list of tuples to multiple lists in Python | null | zip(*[(1, 2), (3, 4), (5, 6)]) |
38,251,245 | Create a list of tuples with adjacent list elements if a condition is true | create a list of tuples which contains number 9 and the number before it, for each occurrence of 9 in the list 'myList' | [(x, y) for x, y in zip(myList, myList[1:]) if y == 9] |
29,983,106 | How can i set proxy with authentication in selenium chrome web driver using python | navigate to webpage given by url `http://www.python.org` using Selenium | driver.get('http://www.google.com.br') |
34,015,615 | Python reversing an UTF-8 string | reverse a UTF-8 string 'a' | b = a.decode('utf8')[::-1].encode('utf8') |
3,276,180 | Extracting date from a string in Python | extract date from a string 'monkey 2010-07-32 love banana' | dparser.parse('monkey 2010-07-32 love banana', fuzzy=True) |
3,276,180 | Extracting date from a string in Python | extract date from a string 'monkey 20/01/1980 love banana' | dparser.parse('monkey 20/01/1980 love banana', fuzzy=True) |
3,276,180 | Extracting date from a string in Python | extract date from a string `monkey 10/01/1980 love banana` | dparser.parse('monkey 10/01/1980 love banana', fuzzy=True) |
16,374,540 | Efficient way to convert a list to dictionary | 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'])) |
9,072,844 | How can I check if a string contains ANY letters from the alphabet? | check if string `the_string` contains any upper or lower-case ASCII letters | re.search('[a-zA-Z]', the_string) |
10,373,660 | Converting a Pandas GroupBy object to DataFrame | convert a pandas `df1` groupby object to dataframe | DataFrame({'count': df1.groupby(['Name', 'City']).size()}).reset_index() |
1,249,388 | Removing all non-numeric characters from string in Python | remove all non-numeric characters from string `sdkjh987978asd098as0980a98sd ` | re.sub('[^0-9]', '', 'sdkjh987978asd098as0980a98sd') |
15,474,933 | List comprehension with if statement | get items from list `a` that don't appear in list `b` | [y for y in a if y not in b] |
40,987,319 | How to subset a dataset in pandas dataframe? | extract the first four rows of the column `ID` from a pandas dataframe `df` | df.groupby('ID').head(4) |
12,974,474 | How to unzip a list of tuples into individual lists? | Unzip a list of tuples `l` into a list of lists | zip(*l) |
7,271,385 | How do I combine two lists into a dictionary in Python? | combine two lists `[1, 2, 3, 4]` and `['a', 'b', 'c', 'd']` into a dictionary | dict(zip([1, 2, 3, 4], ['a', 'b', 'c', 'd'])) |
7,271,385 | How do I combine two lists into a dictionary in Python? | combine two lists `[1, 2, 3, 4]` and `['a', 'b', 'c', 'd']` into a dictionary | dict(zip([1, 2, 3, 4], ['a', 'b', 'c', 'd'])) |
15,974,730 | How do I get the different parts of a Flask request's url? | retrieve the path from a Flask request | request.url |
11,755,208 | How to remove ^M from a text file and replace it with the next line | replace carriage return in string `somestring` with empty string '' | somestring.replace('\\r', '') |
715,550 | Best way to encode tuples with json | serialize dictionary `d` as a JSON formatted string with each key formatted to pattern '%d,%d' | simplejson.dumps(dict([('%d,%d' % k, v) for k, v in list(d.items())])) |
466,345 | Converting string into datetime | parse string "Jun 1 2005 1:33PM" into datetime by format "%b %d %Y %I:%M%p" | datetime.strptime('Jun 1 2005 1:33PM', '%b %d %Y %I:%M%p') |
466,345 | Converting string into datetime | parse string "Aug 28 1999 12:00AM" into datetime | parser.parse('Aug 28 1999 12:00AM') |
17,057,544 | Python - Extract folder path from file path | Get absolute folder path and filename for file `existGDBPath ` | os.path.split(os.path.abspath(existGDBPath)) |
17,057,544 | Python - Extract folder path from file path | extract folder path from file path | os.path.dirname(os.path.abspath(existGDBPath)) |
9,733,638 | Post JSON using Python Requests | Execute a post request to url `http://httpbin.org/post` with json data `{'test': 'cheers'}` | requests.post('http://httpbin.org/post', json={'test': 'cheers'}) |
42,260,840 | Python - Remove dictionary from list if key is equal to value | remove dictionary from list `a` if the value associated with its key 'link' is in list `b` | a = [x for x in a if x['link'] not in b] |
9,647,586 | Getting a request parameter in Jinja2 | get a request parameter `a` in jinja2 | {{request.args.get('a')}} |
18,265,935 | Python - Create list with numbers between 2 values? | create a list of integers between 2 values `11` and `17` | list(range(11, 17)) |
40,707,158 | type conversion in python from int to float | Change data type of data in column 'grade' of dataframe `data_df` into float and then to int | data_df['grade'] = data_df['grade'].astype(float).astype(int) |
4,800,419 | Sorting or Finding Max Value by the second element in a nested list. Python | Find the list in a list of lists `alkaline_earth_values` with the max value of the second element. | max(alkaline_earth_values, key=lambda x: x[1]) |
13,142,347 | How to remove leading and trailing zeros in a string? Python | remove leading and trailing zeros in the string 'your_Strip' | your_string.strip('0') |
14,169,122 | Generating all unique pair permutations | generate a list of all unique pairs of integers in `range(9)` | list(permutations(list(range(9)), 2)) |
587,345 | Python regular expression matching a multiline block of text | create a regular expression that matches the pattern '^(.+)(?:\\n|\\r\\n?)((?:(?:\\n|\\r\\n?).+)+)' over multiple lines of text | re.compile('^(.+)(?:\\n|\\r\\n?)((?:(?:\\n|\\r\\n?).+)+)', re.MULTILINE) |
587,345 | Python regular expression matching a multiline block of text | regular expression "^(.+)\\n((?:\\n.+)+)" matching a multiline block of text | re.compile('^(.+)\\n((?:\\n.+)+)', re.MULTILINE) |
33,218,968 | How do you call a python file that requires a command line argument from within another python file? | Run 'test2.py' file with python location 'path/to/python' and arguments 'neededArgumetGoHere' as a subprocess | call(['path/to/python', 'test2.py', 'neededArgumetGoHere']) |
1,683,775 | Sort a multidimensional list by a variable number of keys | sort a multidimensional list `a` by second and third column | a.sort(key=operator.itemgetter(2, 3)) |
3,523,048 | Add another tuple to a tuple | Add a tuple with value `another_choice` to a tuple `my_choices` | final_choices = ((another_choice,) + my_choices) |
3,523,048 | Add another tuple to a tuple | Add a tuple with value `another_choice` to a tuple `my_choices` | final_choices = ((another_choice,) + my_choices) |
5,137,497 | Find current directory and file's directory | find the current directory | os.getcwd() |
5,137,497 | Find current directory and file's directory | find the current directory | os.path.realpath(__file__) |
5,137,497 | Find current directory and file's directory | get the directory name of `path` | os.path.dirname(path) |
5,137,497 | Find current directory and file's directory | get the canonical path of file `path` | os.path.realpath(path) |
5,137,497 | Find current directory | Find name of current directory | dir_path = os.path.dirname(os.path.realpath(__file__)) |
5,137,497 | Find current directory | Find current directory | cwd = os.getcwd() |
5,137,497 | Find current directory | Find the full path of current directory | full_path = os.path.realpath(__file__) |
10,078,470 | Sort numpy matrix row values in ascending order | sort array `arr` in ascending order by values of the 3rd column | arr[arr[:, (2)].argsort()] |
10,078,470 | Sort numpy matrix row values in ascending order | sort rows of numpy matrix `arr` in ascending order according to all column values | numpy.sort(arr, axis=0) |
373,459 | split string on a number of different characters | split string 'a b.c' on space " " and dot character "." | re.split('[ .]', 'a b.c') |
36,875,258 | copying one file's contents to another in python | copy the content of file 'file.txt' to file 'file2.txt' | shutil.copy('file.txt', 'file2.txt') |
18,319,101 | What's the best way to generate random strings of a specific length in Python? | generate random upper-case ascii string of 12 characters length | print(''.join(choice(ascii_uppercase) for i in range(12))) |
39,646,401 | How to merge the elements in a list sequentially in python | merge the elements in a list `lst` sequentially | [''.join(seq) for seq in zip(lst, lst[1:])] |
19,758,364 | python: rename single column header in pandas dataframe | rename column 'gdp' in dataframe `data` to 'log(gdp)' | data.rename(columns={'gdp': 'log(gdp)'}, inplace=True) |
14,694,482 | Converting html to text with Python | convert a beautiful soup html `soup` to text | print(soup.get_text()) |
18,142,090 | python: sort a list of lists by an item in the sublist | Sort list `li` in descending order based on the second element of each list inside list`li` | sorted(li, key=operator.itemgetter(1), reverse=True) |
31,888,871 | Pandas - replacing column values | replace value 0 with 'Female' and value 1 with 'Male' in column 'sex' of dataframe `data` | data['sex'].replace([0, 1], ['Female', 'Male'], inplace=True) |
19,894,478 | Regex punctuation split [Python] | split string 'Words, words, words.' on punctuation | re.split('\\W+', 'Words, words, words.') |
3,329,386 | Limit the number of sentences in a string | Extract first two substrings in string `phrase` that end in `.`, `?` or `!` | re.match('(.*?[.?!](?:\\s+.*?[.?!]){0,1})', phrase).group(1) |
9,505,526 | Split string into strings of repeating elements | split string `s` into strings of repeating elements | print([a for a, b in re.findall('((\\w)\\2*)', s)]) |
29,360,607 | How does this function to remove duplicate characters from a string in python work? | Create new string with unique characters from `s` seperated by ' ' | print(' '.join(OrderedDict.fromkeys(s))) |
29,360,607 | How does this function to remove duplicate characters from a string in python work? | create a set from string `s` to remove duplicate characters | print(' '.join(set(s))) |
6,510,477 | How can i list only the folders in zip archive in Python? | list folders in zip file 'file' that ends with '/' | [x for x in file.namelist() if x.endswith('/')] |
11,300,383 | How to find the count of a word in a string? | find the count of a word 'Hello' in a string `input_string` | input_string.count('Hello') |
27,436,748 | Python: reduce (list of strings) -> string | reduce the first element of list of strings `data` to a string, separated by '.' | print('.'.join([item[0] for item in data])) |
14,332,141 | Dumping subprcess output in a file in append mode | Move the cursor of file pointer `fh1` at the end of the file. | fh1.seek(2) |
15,852,295 | list of ints into a list of tuples python | convert a flat list into a list of tuples of every two items in the list, in order | print(zip(my_list[0::2], my_list[1::2])) |
15,852,295 | list of ints into a list of tuples python | group a list of ints into a list of tuples of each 2 elements | my_new_list = zip(my_list[0::2], my_list[1::2]) |
21,129,020 | How to fix: "UnicodeDecodeError: 'ascii' codec can't decode byte" | set the default encoding to 'utf-8' | sys.setdefaultencoding('utf8') |
7,999,935 | Python datetime to string without microsecond component | 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') |
36,661,837 | How to retrieve only arabic texts from a string using regular expression? | retrieve arabic texts from string `my_string` | print(re.findall('[\\u0600-\\u06FF]+', my_string)) |
11,073,609 | How to group DataFrame by a period of time? | group dataframe `df` based on minute interval | df.groupby(df.index.map(lambda t: t.minute)) |
5,404,665 | Accessing elements of python dictionary | access value associated with key 'American' of key 'Apple' from dictionary `dict` | dict['Apple']['American'] |
14,991,195 | How to remove rows with null values from kth column onward in python | remove all null values from columns 'three', 'four' and 'five' of dataframe `df2` | df2.dropna(subset=['three', 'four', 'five'], how='all') |