text stringlengths 4 1.08k |
|---|
"split string ""jvm.args= -Dappdynamics.com=true, -Dsomeotherparam=false,"" on the first occurrence of delimiter '='","""""""jvm.args= -Dappdynamics.com=true, -Dsomeotherparam=false,"""""".split('=', 1)" |
print numbers in list `list` with precision of 3 decimal places,"print('[%s]' % ', '.join('%.3f' % val for val in list))" |
format print output of list of floats `l` to print only up to 3 decimal points,"print('[' + ', '.join('%5.3f' % v for v in l) + ']')" |
print a list of floating numbers `l` using string formatting,print([('%5.3f' % val) for val in l]) |
Change the current directory one level up,os.chdir('..') |
print a unicode string `text`,print(text.encode('windows-1252')) |
convert string representation `s2` of binary string rep of integer to floating point number,"struct.unpack('d', struct.pack('Q', int(s2, 0)))[0]" |
convert a binary '-0b1110' to a float number,"float(int('-0b1110', 0))" |
convert a binary `b8` to a float number,"struct.unpack('d', b8)[0]" |
plot a bar graph from the column 'color' in the DataFrame 'df',df.colour.value_counts().plot(kind='bar') |
plot categorical data in series `df` with kind `bar` using pandas and matplotlib,df.groupby('colour').size().plot(kind='bar') |
strip and split each line `line` on white spaces,line.strip().split(' ') |
apply functions `mean` and `std` to each column in dataframe `df`,"df.groupby(lambda idx: 0).agg(['mean', 'std'])" |
sort dictionary `tag_weight` in reverse order by values cast to integers,"sorted(list(tag_weight.items()), key=lambda x: int(x[1]), reverse=True)" |
find the largest integer less than `x`,int(math.ceil(x)) - 1 |
check if the string `myString` is empty,"if (not myString): |
pass" |
check if string `some_string` is empty,"if (not some_string): |
pass" |
check if string `my_string` is empty,"if (not my_string): |
pass" |
check if string `my_string` is empty,"if some_string: |
pass" |
iterate over a dictionary `d` in sorted order,it = iter(sorted(d.items())) |
iterate over a dictionary `d` in sorted order,"for (key, value) in sorted(d.items()): |
pass" |
iterate over a dictionary `dict` in sorted order,return sorted(dict.items()) |
iterate over a dictionary `dict` in sorted order,return iter(sorted(dict.items())) |
iterate over a dictionary `foo` in sorted order,"for (k, v) in sorted(foo.items()): |
pass" |
iterate over a dictionary `foo` sorted by the key,"for k in sorted(foo.keys()): |
pass" |
assign the index of the last occurence of `x` in list `s` to the variable `last`,last = len(s) - s[::-1].index(x) - 1 |
concatenating values in `list1` to a string,str1 = ''.join(list1) |
"concatenating values in list `L` to a string, separate by space",' '.join((str(x) for x in L)) |
concatenating values in `list1` to a string,str1 = ''.join((str(e) for e in list1)) |
concatenating values in list `L` to a string,"makeitastring = ''.join(map(str, L))" |
remove None value from list `L`,[x for x in L if x is not None] |
"select a random element from array `[1, 2, 3]`","random.choice([1, 2, 3])" |
creating a 5x6 matrix filled with `None` and save it as `x`,x = [[None for _ in range(5)] for _ in range(6)] |
create a new 2D array with 2 random rows from array `A`,"A[(np.random.choice(A.shape[0], 2, replace=False)), :]" |
create a new 2 dimensional array containing two random rows from array `A`,"A[(np.random.randint(A.shape[0], size=2)), :]" |
combining rows in pandas by adding their values,df.groupby(df.index).sum() |
find all `owl:Class` tags by parsing xml with namespace,root.findall('{http://www.w3.org/2002/07/owl#}Class') |
generate a random string of length `x` containing lower cased ASCII letters,""""""""""""".join(random.choice(string.lowercase) for x in range(X))" |
add a path `/path/to/2014_07_13_test` to system path,sys.path.append('/path/to/2014_07_13_test') |
round number `x` to nearest integer,int(round(x)) |
round number `h` to nearest integer,h = int(round(h)) |
round number 32.268907563 up to 3 decimal points,"round(32.268907563, 3)" |
round number `value` up to `significantDigit` decimal places,"round(value, significantDigit)" |
round number 1.0005 up to 3 decimal places,"round(1.0005, 3)" |
round number 2.0005 up to 3 decimal places,"round(2.0005, 3)" |
round number 3.0005 up to 3 decimal places,"round(3.0005, 3)" |
round number 4.0005 up to 3 decimal places,"round(4.0005, 3)" |
round number 8.005 up to 2 decimal places,"round(8.005, 2)" |
round number 7.005 up to 2 decimal places,"round(7.005, 2)" |
round number 6.005 up to 2 decimal places,"round(6.005, 2)" |
round number 1.005 up to 2 decimal places,"round(1.005, 2)" |
fill missing value in one column 'Cat1' with the value of another column 'Cat2',df['Cat1'].fillna(df['Cat2']) |
convert the argument `date` with string formatting in logging,"logging.info('date=%s', date)" |
Log message of level 'info' with value of `date` in the message,logging.info('date={}'.format(date)) |
convert values in dictionary `d` into integers,"{k: int(v) for k, v in d.items()}" |
sum elements at the same index of each list in list `lists`,"map(sum, zip(*lists))" |
Convert a string `s` containing hex bytes to a hex string,s.decode('hex') |
convert a string `s` containing hex bytes to a hex string,binascii.a2b_hex(s) |
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') |
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') |
set the value of cell `['x']['C']` equal to 10 in dataframe `df`,df['x']['C'] = 10 |
normalize the dataframe `df` along the rows,np.sqrt(np.square(df).sum(axis=1)) |
remove identical items from list `my_list` and sort it alphabetically,sorted(set(my_list)) |
find the index of the element with the maximum value from a list 'a'.,"max(enumerate(a), key=lambda x: x[1])[0]" |
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] |
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]" |
grab one random item from a database `model` in django/postgresql,model.objects.all().order_by('?')[0] |
"run python script 'script2.py' from another python script, passing in 1 as an argument",os.system('script2.py 1') |
python regex for hyphenated words in `text`,"re.findall('\\w+(?:-\\w+)+', text)" |
create variable key/value pairs with argparse,"parser.add_argument('--conf', nargs=2, action='append')" |
Get `3` unique items from a list,"random.sample(list(range(1, 16)), 3)" |
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))" |
sort a list of strings `strings` based on regex match,"strings.sort(key=lambda str: re.sub('.*%', '', str))" |
Create list `listy` containing 3 empty lists,listy = [[] for i in range(3)] |
sort numpy float array `A` column by column,"A = np.array(sorted(A, key=tuple))" |
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'] |
"trim string "" Hello """,' Hello '.strip() |
trim string `myString `,myString.strip() |
"Trimming a string "" Hello """,' Hello '.strip() |
"Trimming a string "" Hello""",' Hello'.strip() |
"Trimming a string ""Bob has a cat""",'Bob has a cat'.strip() |
"Trimming a string "" Hello """,' Hello '.strip() |
Trimming a string `str`,str.strip() |
"Trimming ""\n"" from string `myString`",myString.strip('\n') |
"left trimming ""\n\r"" from string `myString`",myString.lstrip('\n\r') |
"right trimming ""\n\t"" from string `myString`",myString.rstrip('\n\t') |
"Trimming a string "" Hello\n"" by space",' Hello\n'.strip(' ') |
"sort a list of tuples 'unsorted' based on two elements, second and third","sorted(unsorted, key=lambda element: (element[1], element[2]))" |
decode string `content` to UTF-8 code,print(content.decode('utf8')) |
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)" |
"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]) |
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'])" |
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'])" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.