idx
int64
0
2.38k
question
stringlengths
5
184
target
stringlengths
5
213
2,200
find the magnitude (length) squared of a vector `vf` field
np . einsum ( '...j,...j->...' , vf , vf )
2,201
request http url `url`
r = requests . get ( url )
2,202
request http url `url` with parameters `payload`
r = requests . get ( url , params = payload )
2,203
post request url `url` with parameters `payload`
r = requests . post ( url , data = payload )
2,204
make an HTTP post request with data `post_data`
post_response = requests . post ( url = 'http://httpbin.org/post' , json = post_data )
2,205
django jinja slice list `mylist` by '3:8'
{ { ( mylist | slice ) : '3:8' } }
2,206
create dataframe `df` with content of hdf store file '/home/.../data.h5' with key of 'firstSet'
df1 = pd . read_hdf ( '/home/.../data.h5' , 'firstSet' )
2,207
get the largest index of the last occurrence of characters '([{' in string `test_string`
max ( test_string . rfind ( i ) for i in '([{' )
2,208
print 'here is your checkmark: ' plus unicode character u'\u2713'
print ( 'here is your checkmark: ' + '\u2713' )
2,209
print unicode characters in a string `\u0420\u043e\u0441\u0441\u0438\u044f`
print ( '\u0420\u043e\u0441\u0441\u0438\u044f' )
2,210
pads string '5' on the left with 1 zero
print ( '{0}' . format ( '5' . zfill ( 2 ) ) )
2,211
Remove duplicates elements from list `sequences` and sort it in ascending order
sorted ( set ( itertools . chain . from_iterable ( sequences ) ) )
2,212
pandas dataframe `df` column 'a' to list
df [ 'a' ] . values . tolist ( )
2,213
Get a list of all values in column `a` in pandas data frame `df`
df [ 'a' ] . tolist ( )
2,214
escaping quotes in string
replace ( '"' , '\\"' )
2,215
check if all string elements in list `words` are upper-cased
print ( all ( word [ 0 ] . isupper ( ) for word in words ) )
2,216
remove items from dictionary `myDict` if the item's value `val` is equal to 42
myDict = { key : val for key , val in list ( myDict . items ( ) ) if val != 42 }
2,217
Remove all items from a dictionary `myDict` whose values are `42`
{ key : val for key , val in list ( myDict . items ( ) ) if val != 42 }
2,218
Determine the byte length of a utf-8 encoded string `s`
return len ( s . encode ( 'utf-8' ) )
2,219
kill a process with id `process.pid`
os . kill ( process . pid , signal . SIGKILL )
2,220
get data of columns with Null values in dataframe `df`
df [ pd . isnull ( df ) . any ( axis = 1 ) ]
2,221
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'
2,222
Parse a file `sample.xml` using expat parsing in python 3
parser . ParseFile ( open ( 'sample.xml' , 'rb' ) )
2,223
Exit script
sys . exit ( )
2,224
assign value in `group` dynamically to class property `attr`
setattr ( self , attr , group )
2,225
decode url-encoded string `some_string` to its character equivalents
urllib . parse . unquote ( urllib . parse . unquote ( some_string ) )
2,226
decode a double URL encoded string 'FireShot3%2B%25282%2529.png' to 'FireShot3+(2).png'
urllib . parse . unquote ( urllib . parse . unquote ( 'FireShot3%2B%25282%2529.png' ) )
2,227
change flask security register url to `/create_account`
app . config [ 'SECURITY_REGISTER_URL' ] = '/create_account'
2,228
open a file `/home/user/test/wsservice/data.pkl` in binary write mode
output = open ( '/home/user/test/wsservice/data.pkl' , 'wb' )
2,229
remove the last element in list `a`
del a [ ( - 1 ) ]
2,230
remove the element in list `a` with index 1
a . pop ( 1 )
2,231
remove the last element in list `a`
a . pop ( )
2,232
remove the element in list `a` at index `index`
a . pop ( index )
2,233
remove the element in list `a` at index `index`
del a [ index ]
2,234
print a celsius symbol on x axis of a plot `ax`
ax . set_xlabel ( 'Temperature (\u2103)' )
2,235
Print a celsius symbol with matplotlib
ax . set_xlabel ( 'Temperature ($^\\circ$C)' )
2,236
convert a list of lists `list_of_lists` into a list of strings keeping empty sub-lists as empty string ''
[ '' . join ( l ) for l in list_of_lists ]
2,237
get a list of all the duplicate items in dataframe `df` using pandas
pd . concat ( g for _ , g in df . groupby ( 'ID' ) if len ( g ) > 1 )
2,238
Delete third row in a numpy array `x`
x = numpy . delete ( x , 2 , axis = 1 )
2,239
delete first row of array `x`
x = numpy . delete ( x , 0 , axis = 0 )
2,240
merge rows from dataframe `df1` with rows from dataframe `df2` and calculate the mean for rows that have the same value of axis 1
pd . concat ( ( df1 , df2 ) , axis = 1 ) . mean ( axis = 1 )
2,241
Get the average values from two numpy arrays `old_set` and `new_set`
np . mean ( np . array ( [ old_set , new_set ] ) , axis = 0 )
2,242
Matplotlib change marker size to 500
scatter ( x , y , s = 500 , color = 'green' , marker = 'h' )
2,243
Create new list `result` by splitting each item in list `words`
result = [ item for word in words for item in word . split ( ',' ) ]
2,244
convert JSON string '2012-05-29T19:30:03.283Z' into a DateTime object using format '%Y-%m-%dT%H:%M:%S.%fZ'
datetime . datetime . strptime ( '2012-05-29T19:30:03.283Z' , '%Y-%m-%dT%H:%M:%S.%fZ' )
2,245
count `True` values associated with key 'one' in dictionary `tadas`
sum ( item [ 'one' ] for item in list ( tadas . values ( ) ) )
2,246
encode a pdf file `pdf_reference.pdf` with `base64` encoding
a = open ( 'pdf_reference.pdf' , 'rb' ) . read ( ) . encode ( 'base64' )
2,247
split string `a` using new-line character '\n' as separator
a . rstrip ( ) . split ( '\n' )
2,248
split a string `a` with new line character
a . split ( '\n' ) [ : - 1 ]
2,249
return http status code 204 from a django view
return HttpResponse ( status = 204 )
2,250
check if 7 is in `a`
( 7 in a )
2,251
check if 'a' is in list `a`
( 'a' in a )
2,252
sort list `results` by keys value 'year'
sorted ( results , key = itemgetter ( 'year' ) )
2,253
get current url in selenium webdriver `browser`
print ( browser . current_url )
2,254
split string `str` with delimiter '; ' or delimiter ', '
re . split ( '; |, ' , str )
2,255
un-escaping characters in a string with python
"""\\u003Cp\\u003E""" . decode ( 'unicode-escape' )
2,256
convert date string `s` in format pattern '%d/%m/%Y' into a timestamp
time . mktime ( datetime . datetime . strptime ( s , '%d/%m/%Y' ) . timetuple ( ) )
2,257
convert string '01/12/2011' to an integer timestamp
int ( datetime . datetime . strptime ( '01/12/2011' , '%d/%m/%Y' ) . strftime ( '%s' ) )
2,258
get http header of the key 'your-header-name' in flask
request . headers [ 'your-header-name' ]
2,259
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 )
2,260
Get data of dataframe `df` where the sum of column 'X' grouped by column 'User' is equal to 0
df . loc [ df . groupby ( 'User' ) [ 'X' ] . transform ( sum ) == 0 ]
2,261
Get data from dataframe `df` where column 'X' is equal to 0
df . groupby ( 'User' ) [ 'X' ] . transform ( sum ) == 0
2,262
How do I find an element that contains specific text in Selenium Webdriver (Python)?
driver . find_elements_by_xpath ( "//*[contains(text(), 'My Button')]" )
2,263
convert pandas group by object to multi-indexed dataframe with indices 'Name' and 'Destination'
df . set_index ( [ 'Name' , 'Destination' ] )
2,264
coalesce non-word-characters in string `a`
print ( re . sub ( '(\\W)\\1+' , '\\1' , a ) )
2,265
open a file "$file" under Unix
os . system ( 'start "$file"' )
2,266
Convert a Unicode string `title` to a 'ascii' string
unicodedata . normalize ( 'NFKD' , title ) . encode ( 'ascii' , 'ignore' )
2,267
Convert a Unicode string `a` to a 'ascii' string
a . encode ( 'ascii' , 'ignore' )
2,268
create a list `files` containing all files in directory '.' that starts with numbers between 0 and 9 and ends with the extension '.jpg'
files = [ f for f in os . listdir ( '.' ) if re . match ( '[0-9]+.*\\.jpg' , f ) ]
2,269
adding a 1-d array `[1, 2, 3, 4, 5, 6, 7, 8, 9]` to a 3-d array `np.zeros((6, 9, 20))`
np . zeros ( ( 6 , 9 , 20 ) ) + np . array ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ) [ ( None ) , : , ( None ) ]
2,270
add array of shape `(6, 9, 20)` to array `[1, 2, 3, 4, 5, 6, 7, 8, 9]`
np . zeros ( ( 6 , 9 , 20 ) ) + np . array ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ) . reshape ( ( 1 , 9 , 1 ) )
2,271
How can I launch an instance of an application using Python?
os . system ( 'start excel.exe <path/to/file>' )
2,272
get the list with the highest sum value in list `x`
print ( max ( x , key = sum ) )
2,273
sum the length of lists in list `x` that are more than 1 item in length
sum ( len ( y ) for y in x if len ( y ) > 1 )
2,274
Enclose numbers in quotes in a string `This is number 1 and this is number 22`
re . sub ( '(\\d+)' , '"\\1"' , 'This is number 1 and this is number 22' )
2,275
multiply the columns of sparse matrix `m` by array `a` then multiply the rows of the resulting matrix by array `a`
numpy . dot ( numpy . dot ( a , m ) , a )
2,276
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 ( )
2,277
sort a nested list by the inverse of element 2, then by element 1
sorted ( l , key = lambda x : ( - int ( x [ 1 ] ) , x [ 0 ] ) )
2,278
get domain/host name from request object in Django
request . META [ 'HTTP_HOST' ]
2,279
get a string `randomkey123xyz987` between two substrings in a string `api('randomkey123xyz987', 'key', 'text')` using regex
re . findall ( "api\\('(.*?)'" , "api('randomkey123xyz987', 'key', 'text')" )
2,280
invoke perl script './uireplace.pl' using perl interpeter '/usr/bin/perl' and send argument `var` to it
subprocess . call ( [ '/usr/bin/perl' , './uireplace.pl' , var ] )
2,281
print list of items `myList`
print ( '\n' . join ( str ( p ) for p in myList ) )
2,282
update the dictionary `mydic` with dynamic keys `i` and values with key 'name' from dictionary `o`
mydic . update ( { i : o [ 'name' ] } )
2,283
split a `utf-8` encoded string `stru` into a list of characters
list ( stru . decode ( 'utf-8' ) )
2,284
convert utf-8 with bom string `s` to utf-8 with no bom `u`
u = s . decode ( 'utf-8-sig' )
2,285
Filter model 'Entry' where 'id' is not equal to 3 in Django
Entry . objects . filter ( ~ Q ( id = 3 ) )
2,286
lookup an attribute in any scope by name 'range'
getattr ( __builtins__ , 'range' )
2,287
restart a computer after `900` seconds using subprocess
subprocess . call ( [ 'shutdown' , '/r' , '/t' , '900' ] )
2,288
shutdown a computer using subprocess
subprocess . call ( [ 'shutdown' , '/s' ] )
2,289
abort a computer shutdown using subprocess
subprocess . call ( [ 'shutdown' , '/a ' ] )
2,290
logoff computer having windows operating system using python
subprocess . call ( [ 'shutdown' , '/l ' ] )
2,291
shutdown and restart a computer running windows from script
subprocess . call ( [ 'shutdown' , '/r' ] )
2,292
erase the contents of a file `filename`
open ( 'filename' , 'w' ) . close ( )
2,293
How to erase the file contents of text file in Python?
open ( 'file.txt' , 'w' ) . close ( )
2,294
convert dataframe `df` to list of dictionaries including the index values
df . to_dict ( 'index' )
2,295
Create list of dictionaries from pandas dataframe `df`
df . to_dict ( 'records' )
2,296
Group a pandas data frame by monthly frequenct `M` using groupby
df . groupby ( pd . TimeGrouper ( freq = 'M' ) )
2,297
divide the members of a list `conversions` by the corresponding members of another list `trials`
[ ( c / t ) for c , t in zip ( conversions , trials ) ]
2,298
sort dict `data` by value
sorted ( data , key = data . get )
2,299
Sort a dictionary `data` by its values
sorted ( data . values ( ) )