question_id
int64 1.48k
42.8M
| intent
stringlengths 11
122
| rewritten_intent
stringlengths 4
183
⌀ | snippet
stringlengths 2
232
|
---|---|---|---|
14,262,654 |
Numpy: Get random set of rows from 2D array
|
create a new 2D array with 2 random rows from array `A`
|
A[(np.random.choice(A.shape[0], 2, replace=False)), :]
|
14,262,654 |
Numpy: Get random set of rows from 2D array
|
create a new 2 dimensional array containing two random rows from array `A`
|
A[(np.random.randint(A.shape[0], size=2)), :]
|
17,438,906 |
Combining rows in pandas
|
combining rows in pandas by adding their values
|
df.groupby(df.index).sum()
|
14,853,243 |
Parsing XML with namespace in Python via 'ElementTree'
|
find all `owl:Class` tags by parsing xml with namespace
|
root.findall('{http://www.w3.org/2002/07/owl#}Class')
|
1,957,273 |
How do I generate a random string (of length X, a-z only) in Python?
|
generate a random string of length `x` containing lower cased ASCII letters
|
"""""".join(random.choice(string.lowercase) for x in range(X))
|
24,722,212 |
Python cant find module in the same folder
|
add a path `/path/to/2014_07_13_test` to system path
|
sys.path.append('/path/to/2014_07_13_test')
|
31,818,050 |
round number to nearest integer
|
round number `x` to nearest integer
|
int(round(x))
|
31,818,050 |
round number to nearest integer
|
round number `h` to nearest integer
|
h = int(round(h))
|
31,818,050 |
round number to nearest integer
|
round number 32.268907563 up to 3 decimal points
|
round(32.268907563, 3)
|
31,818,050 |
round number to nearest integer
|
round number `value` up to `significantDigit` decimal places
|
round(value, significantDigit)
|
31,818,050 |
round number to nearest integer
|
round number 1.0005 up to 3 decimal places
|
round(1.0005, 3)
|
31,818,050 |
round number to nearest integer
|
round number 2.0005 up to 3 decimal places
|
round(2.0005, 3)
|
31,818,050 |
round number to nearest integer
|
round number 3.0005 up to 3 decimal places
|
round(3.0005, 3)
|
31,818,050 |
round number to nearest integer
|
round number 4.0005 up to 3 decimal places
|
round(4.0005, 3)
|
31,818,050 |
round number to nearest integer
|
round number 8.005 up to 2 decimal places
|
round(8.005, 2)
|
31,818,050 |
round number to nearest integer
|
round number 7.005 up to 2 decimal places
|
round(7.005, 2)
|
31,818,050 |
round number to nearest integer
|
round number 6.005 up to 2 decimal places
|
round(6.005, 2)
|
31,818,050 |
round number to nearest integer
|
round number 1.005 up to 2 decimal places
|
round(1.005, 2)
|
30,357,276 |
Pandas - FillNa with another column
|
fill missing value in one column 'Cat1' with the value of another column 'Cat2'
|
df['Cat1'].fillna(df['Cat2'])
|
12,843,099 |
Python: Logging TypeError: not all arguments converted during string formatting
|
convert the argument `date` with string formatting in logging
|
logging.info('date=%s', date)
|
12,843,099 |
Python: Logging TypeError: not all arguments converted during string formatting
|
Log message of level 'info' with value of `date` in the message
|
logging.info('date={}'.format(date))
|
9,224,385 |
In dictionary, converting the value from string to integer
|
convert values in dictionary `d` into integers
|
{k: int(v) for k, v in d.items()}
|
11,280,536 |
How can I add the corresponding elements of several lists of numbers?
|
sum elements at the same index of each list in list `lists`
|
map(sum, zip(*lists))
|
10,824,319 |
Python: How to convert a string containing hex bytes to a hex string
|
Convert a string `s` containing hex bytes to a hex string
|
s.decode('hex')
|
10,824,319 |
Python: How to convert a string containing hex bytes to a hex string
|
convert a string `s` containing hex bytes to a hex string
|
binascii.a2b_hex(s)
|
40,851,413 |
MITM proxy over SSL hangs on wrap_socket with client
|
send data 'HTTP/1.0 200 OK\r\n\r\n' to socket `connection`
|
connection.send('HTTP/1.0 200 established\r\n\r\n')
|
40,851,413 |
MITM proxy over SSL hangs on wrap_socket with client
|
send data 'HTTP/1.0 200 OK\r\n\r\n' to socket `connection`
|
connection.send('HTTP/1.0 200 OK\r\n\r\n')
|
13,842,088 |
Set value for particular cell in pandas DataFrame
|
set the value of cell `['x']['C']` equal to 10 in dataframe `df`
|
df['x']['C'] = 10
|
18,524,112 |
Norm along row in pandas
|
normalize the dataframe `df` along the rows
|
np.sqrt(np.square(df).sum(axis=1))
|
22,741,068 |
How do I remove identical items from a list and sort it in Python?
|
remove identical items from list `my_list` and sort it alphabetically
|
sorted(set(my_list))
|
11,530,799 |
Python Finding Index of Maximum in List
|
find the index of the element with the maximum value from a list 'a'.
|
max(enumerate(a), key=lambda x: x[1])[0]
|
17,117,912 |
Python Accessing Values in A List of Dictionaries
|
create a list where each element is a value of the key 'Name' for each dictionary `d` in the list `thisismylist`
|
[d['Name'] for d in thisismylist]
|
17,117,912 |
Python Accessing Values in A List of Dictionaries
|
create a list of tuples with the values of keys 'Name' and 'Age' from each dictionary `d` in the list `thisismylist`
|
[(d['Name'], d['Age']) for d in thisismylist]
|
9,354,127 |
How to grab one random item from a database in Django/postgreSQL?
|
grab one random item from a database `model` in django/postgresql
|
model.objects.all().order_by('?')[0]
|
3,781,851 |
Run a python script from another python script, passing in args
|
run python script 'script2.py' from another python script, passing in 1 as an argument
|
os.system('script2.py 1')
|
8,383,213 |
Python Regex for hyphenated words
|
python regex for hyphenated words in `text`
|
re.findall('\\w+(?:-\\w+)+', text)
|
27,146,262 |
Create variable key/value pairs with argparse (python)
|
create variable key/value pairs with argparse
|
parser.add_argument('--conf', nargs=2, action='append')
|
6,494,508 |
How do you pick "x" number of unique numbers from a list in Python?
|
Get `3` unique items from a list
|
random.sample(list(range(1, 16)), 3)
|
1,082,413 |
Sort a list of strings based on regular expression match or something similar
|
sort list `strings` in alphabetical order based on the letter after percent character `%` in each element
|
strings.sort(key=lambda str: re.sub('.*%(.).*', '\\1', str))
|
1,082,413 |
Sort a list of strings based on regular expression match or something similar
|
sort a list of strings `strings` based on regex match
|
strings.sort(key=lambda str: re.sub('.*%', '', str))
|
7,745,562 |
Appending to 2D lists in Python
|
Create list `listy` containing 3 empty lists
|
listy = [[] for i in range(3)]
|
12,496,531 |
Sort NumPy float array column by column
|
sort numpy float array `A` column by column
|
A = np.array(sorted(A, key=tuple))
|
18,649,884 |
Python list comprehension for loops
|
Get a list from two strings `12345` and `ab` with values as each character concatenated
|
[(x + y) for x in '12345' for y in 'ab']
|
761,804 |
Trimming a string
|
trim string " Hello "
|
' Hello '.strip()
|
761,804 |
Trimming a string
|
trim string `myString `
|
myString.strip()
|
761,804 |
Trimming a string
|
Trimming a string " Hello "
|
' Hello '.strip()
|
761,804 |
Trimming a string
|
Trimming a string " Hello"
|
' Hello'.strip()
|
761,804 |
Trimming a string
|
Trimming a string "Bob has a cat"
|
'Bob has a cat'.strip()
|
761,804 |
Trimming a string
|
Trimming a string " Hello "
|
' Hello '.strip()
|
761,804 |
Trimming a string
|
Trimming a string `str`
|
str.strip()
|
761,804 |
Trimming a string
|
Trimming "\n" from string `myString`
|
myString.strip('\n')
|
761,804 |
Trimming a string
|
left trimming "\n\r" from string `myString`
|
myString.lstrip('\n\r')
|
761,804 |
Trimming a string
|
right trimming "\n\t" from string `myString`
|
myString.rstrip('\n\t')
|
761,804 |
Trimming a string
|
Trimming a string " Hello\n" by space
|
' Hello\n'.strip(' ')
|
9,376,384 |
Sort a list of tuples depending on two elements
|
sort a list of tuples 'unsorted' based on two elements, second and third
|
sorted(unsorted, key=lambda element: (element[1], element[2]))
|
17,577,727 |
Python, Encoding output to UTF-8
|
decode string `content` to UTF-8 code
|
print(content.decode('utf8'))
|
31,767,173 |
How do I vectorize this loop in numpy?
|
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)
|
42,100,344 |
How to convert efficiently a dataframe column of string type into datetime in Python?
|
convert a dataframe `df`'s column `ID` into datetime, after removing the first and last 3 letters
|
pd.to_datetime(df.ID.str[1:-3])
|
30,190,459 |
How to gracefully fallback to `NaN` value while reading integers from a CSV with Pandas?
|
read CSV file 'my.csv' into a dataframe `df` with datatype of float for column 'my_column' considering character 'n/a' as NaN value
|
df = pd.read_csv('my.csv', dtype={'my_column': np.float64}, na_values=['n/a'])
|
30,190,459 |
How to gracefully fallback to `NaN` value while reading integers from a CSV with Pandas?
|
convert nan values to ‘n/a’ while reading rows from a csv `read_csv` with pandas
|
df = pd.read_csv('my.csv', na_values=['n/a'])
|
798,854 |
All combinations of a list of lists
|
create a list containing all cartesian products of elements in list `a`
|
list(itertools.product(*a))
|
15,886,340 |
How to extract all UPPER from a string? Python
|
remove uppercased characters in string `s`
|
re.sub('[^A-Z]', '', s)
|
5,882,405 |
Get date from ISO week number in Python
|
convert string '2011221' into a DateTime object using format '%Y%W%w'
|
datetime.strptime('2011221', '%Y%W%w')
|
16,883,447 |
How to read a "C source, ISO-8859 text"
|
read file 'myfile' using encoding 'iso-8859-1'
|
codecs.open('myfile', 'r', 'iso-8859-1').read()
|
1,222,677 |
List Comprehensions in Python : efficient selection in a list
|
create a list containing elements from list `list` that are predicate to function `f`
|
[f(x) for x in list]
|
41,807,864 |
Regex matching 5-digit substrings not enclosed with digits
|
regex matching 5-digit substrings not enclosed with digits in `s`
|
re.findall('(?<!\\d)\\d{5}(?!\\d)', s)
|
2,655,956 |
filtering elements from list of lists in Python?
|
create a list containing elements of list `a` if the sum of the element is greater than 10
|
[item for item in a if sum(item) > 10]
|
3,887,469 |
python: how to convert currency to decimal?
|
convert currency string `dollars` to decimal `cents_int`
|
cents_int = int(round(float(dollars.strip('$')) * 100))
|
39,532,974 |
Remove final characters from string recursively - What's the best way to do this?
|
remove letters from string `example_line` if the letter exist in list `bad_chars`
|
"""""".join(dropwhile(lambda x: x in bad_chars, example_line[::-1]))[::-1]
|
2,972,212 |
Creating an empty list
|
Creating an empty list `l`
|
l = []
|
2,972,212 |
Creating an empty list
|
Creating an empty list `l`
|
l = list()
|
2,972,212 |
Creating an empty list
|
Creating an empty list
|
list()
|
2,972,212 |
Creating an empty list
|
Creating an empty list
|
[]
|
13,022,385 |
How to properly quit a program in python
|
properly quit a program
|
sys.exit(0)
|
5,254,445 |
Add string in a certain position in Python
|
add string `-` in `4th` position of a string `s`
|
s[:4] + '-' + s[4:]
|
11,219,949 |
Python : how to append new elements in a list of list?
|
append 3 lists in one list
|
[[] for i in range(3)]
|
11,219,949 |
Python : how to append new elements in a list of list?
|
Initialize a list of empty lists `a` of size 3
|
a = [[] for i in range(3)]
|
20,837,786 |
Changing the referrer URL in python requests
|
request URL `url` using http header `{'referer': my_referer}`
|
requests.get(url, headers={'referer': my_referer})
|
2,849,286 |
Python, Matplotlib, subplot: How to set the axis range?
|
set the y axis range to `0, 1000` in subplot using pylab
|
pylab.ylim([0, 1000])
|
29,034,928 |
Pandas convert a column of list to dummies
|
convert a column of list in series `s` to dummies
|
pd.get_dummies(s.apply(pd.Series).stack()).sum(level=0)
|
3,428,769 |
Finding the largest delta between two integers in a list in python
| null |
max(abs(x - y) for x, y in zip(values[1:], values[:-1]))
|
2,636,755 |
How to convert hex string to integer in Python?
|
convert a hex string `x` to string
|
y = str(int(x, 16))
|
354,038 |
check if a string is a number (float)
|
check if string `a` is an integer
|
a.isdigit()
|
354,038 |
check if a string is a number
|
function to check if a string is a number
|
isdigit()
|
354,038 |
check if a string is a number
|
check if string `b` is a number
|
b.isdigit()
|
18,366,797 |
pandas.read_csv: how to skip comment lines
|
pandas read comma-separated CSV file `s` and skip commented lines starting with '#'
|
pd.read_csv(StringIO(s), sep=',', comment='#')
|
12,604,909 |
Pandas: how to change all the values of a column?
|
pandas: change all the values of a column 'Date' into "int(str(x)[-4:])"
|
df['Date'] = df['Date'].apply(lambda x: int(str(x)[-4:]))
|
4,362,586 |
sum a list of numbers in Python
|
sum a list of numbers `list_of_nums`
|
sum(list_of_nums)
|
6,561,653 |
how to get the index of dictionary with the highest value in a list of dictionary
|
Get an item from a list of dictionary `lst` which has maximum value in the key `score` using lambda function
|
max(lst, key=lambda x: x['score'])
|
3,774,571 |
Get data from the meta tags using BeautifulSoup
|
BeautifulSoup find all tags with attribute 'name' equal to 'description'
|
soup.findAll(attrs={'name': 'description'})
|
39,268,928 |
Python: how to get rid of spaces in str(dict)?
|
remove all spaces from a string converted from dictionary `{'a': 1, 'b': 'as df'}`
|
str({'a': 1, 'b': 'as df'}).replace(': ', ':').replace(', ', ',')
|
39,268,928 |
Python: how to get rid of spaces in str(dict)?
|
convert dictionary `dict` into a string formatted object
|
'{' + ','.join('{0!r}:{1!r}'.format(*x) for x in list(dct.items())) + '}'
|
13,655,392 |
Python- insert a character into a string
|
concatenate items from list `parts` into a string starting from the second element
|
"""""".join(parts[1:])
|
13,655,392 |
Python- insert a character into a string
|
insert a character ',' into a string in front of '+' character in second part of the string
|
""",+""".join(c.rsplit('+', 1))
|
18,397,805 |
How do I delete a row in a numpy array which contains a zero?
|
delete all rows in a numpy array `a` where any value in a row is zero `0`
|
a[np.all(a != 0, axis=1)]
|
8,199,398 |
Extracting only characters from a string in Python
|
extract only alphabetic characters from a string `your string`
|
""" """.join(re.split('[^a-zA-Z]*', 'your string'))
|
8,199,398 |
Extracting only characters from a string in Python
|
Extract only characters from a string as a list
|
re.split('[^a-zA-Z]*', 'your string')
|
2,151,517 |
Create Union of All Values Contained in Multiple Lists
|
get the union set from list of lists `results_list`
|
results_union = set().union(*results_list)
|
2,151,517 |
Create Union of All Values Contained in Multiple Lists
|
get the union of values in list of lists `result_list`
|
return list(set(itertools.chain(*result_list)))
|
36,190,533 |
python: check if an numpy array contains any element of another array
|
check if a numpy array `a1` contains any element of another array `a2`
|
np.any(np.in1d(a1, a2))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.