text
stringlengths 4
1.08k
|
|---|
python - finding the longest sequence with findall,"sorted(re.findall('g+', 'fggfggggfggfg'), key=len, reverse=True)"
|
python string formatting: reference one argument multiple times,"""""""{0} {1} {1}"""""".format('foo', 'bar')"
|
fastest way to sort each row in a pandas dataframe,"df.sort(df.columns, axis=1, ascending=False)"
|
select rows from numpy rec array,array[array['phase'] == 'P']
|
pyqt - how to set qcombobox in a table view using qitemdelegate,return QtCore.Qt.ItemIsEnabled
|
how to delete everything after a certain character in a string?,"s = re.match('^.*?\\.zip', s).group(0)"
|
splitting string and removing whitespace python,"[item.strip() for item in my_string.split(',')]"
|
how to order a list of lists by the first value,"[1, 1, 1] < [1, 1, 2]"
|
create an empty data frame `df2` with index from another data frame `df1`,df2 = pd.DataFrame(index=df1.index)
|
"slice list `[1, 2, 3, 4, 5, 6, 7]` into lists of two elements each","list(grouper(2, [1, 2, 3, 4, 5, 6, 7]))"
|
how to create a group id based on 5 minutes interval in pandas timeseries?,df.groupby(pd.TimeGrouper('5Min'))['val'].apply(lambda x: len(x) > 3)
|
possible to get user input without inserting a new line?,"print('Hello, {0}, how do you do?'.format(input('Enter name here: ')))"
|
how to draw a heart with pylab,plt.show()
|
match blank lines in `s` with regular expressions,"re.split('\n\\s*\n', s)"
|
pandas read comma-separated csv file `s` and skip commented lines starting with '#',"pd.read_csv(StringIO(s), sep=',', comment='#')"
|
how to reverse tuples in python?,x[::-1]
|
convert list of fractions to floats in python,"[(n / d) for n, d in (map(float, i.split('/')) for i in data)]"
|
setting color range in matplotlib patchcollection,plt.show()
|
passing an argument to a python script and opening a file,name = sys.argv[1]
|
get value of the environment variable 'key_that_might_exist',print(os.environ.get('KEY_THAT_MIGHT_EXIST'))
|
find the index of sub string 's' in string `str` starting from index 15,"str.find('s', 15)"
|
how can i disable logging while running unit tests in python django?,logging.disable(logging.CRITICAL)
|
remove characters in '!@#$' from a string `line`,"line = line.translate(string.maketrans('', ''), '!@#$')"
|
how to construct regex for this text,"re.findall('(?<=\\s)\\d.*?(?=\\s\\d\\s\\d[.](?=$|\\s[A-Z]))', s)"
|
url encoding in python,urllib.parse.quote_plus('a b')
|
removing elements from an array that are in another array,"A[np.all(np.any(A - B[:, (None)], axis=2), axis=0)]"
|
dictionary to lowercase in python,"{k.lower(): v.lower() for k, v in list({'My Key': 'My Value'}.items())}"
|
what is the difference between a string and a byte string?,"""""""tornos"""""".encode('utf-8')"
|
check if 2 arrays have at least one element in common?,"np.in1d(A, B).any()"
|
print raw http request in flask or wsgi,app.run()
|
python pickle/unpickle a list to/from a file,pickle.load('afile')
|
python: one-liner to perform an operation upon elements in a 2d array (list of lists)?,[[int(y) for y in x] for x in values]
|
fill list `mylist` with 4 0's,self.myList.extend([0] * (4 - len(self.myList)))
|
change tkinter frame title,root.mainloop()
|
how do i change directories using paramiko?,myssh.exec_command('cd ..; pwd')
|
how to modify pandas plotting integration?,ax.set_xticks([])
|
how to write individual bits to a text file in python?,"struct.pack('h', 824)"
|
numpy array: replace nan values with average of columns,"ma.array(a, mask=np.isnan(a))"
|
print a string using multiple strings `name` and `score`,"print('Total score for %s is %s ' % (name, score))"
|
how do i select from multiple tables in one query with django?,Employee.objects.select_related()
|
how to access the class variable by string in python?,"getattr(test, a_string)"
|
how to replace the white space in a string in a pandas dataframe?,"df.replace(' ', '_', regex=True)"
|
how can i parse a comma delimited string into a list (caveat)?,"['foo', 'bar', 'one, two', 'three four']"
|
get value of the environment variable 'key_that_might_exist' with default value `default_value`,"print(os.getenv('KEY_THAT_MIGHT_EXIST', default_value))"
|
check if list `li` is empty,"if (len(li) == 0):
|
pass"
|
is it possible for beautifulsoup to work in a case-insensitive manner?,"soup.findAll('meta', attrs={'name': re.compile('^description$', re.I)})"
|
how to change the font size on a matplotlib plot,matplotlib.rcParams.update({'font.size': 22})
|
how can i render 3d histograms in python?,plt.show()
|
python: for loop in index assignment,a = [str(wi) for wi in wordids]
|
removing non-ascii characters in a csv file,"b.create_from_csv_row(row.encode('ascii', 'ignore'))"
|
perform different operations based on index modulus of list items,"['One', 'TWO', 'eerhT', 'Four', 'FIVE', 'xiS', 'Seven', 'EIGHT', 'eniN']"
|
"does filter,map, and reduce in python create a new copy of list?",[x for x in list_of_nums if x != 2]
|
how to check if an element from list a is not present in list b in python?,C = [i for i in A if i not in B]
|
converting integer to binary in python,"""""""{0:08b}"""""".format(6)"
|
how to select element with selenium python xpath,"driver.find_element_by_xpath(""//div[@id='a']//a[@class='click']"")"
|
how can i save an image with pil?,"j = Image.fromarray(b, mode='RGB')"
|
find all the elements that consists value '1' in a list of tuples 'a',[item for item in a if 1 in item]
|
convert unicode string '\xd0\xbc\xd0\xb0\xd1\x80\xd0\xba\xd0\xb0' to byte string,'\xd0\xbc\xd0\xb0\xd1\x80\xd0\xba\xd0\xb0'.encode('latin-1')
|
gnuplot linecolor variable in matplotlib?,plt.show()
|
how to hide firefox window (selenium webdriver)?,driver = webdriver.PhantomJS('C:\\phantomjs-1.9.7-windows\\phantomjs.exe')
|
get ip address of url in python?,print(socket.gethostbyname('google.com'))
|
can a list of all member-dict keys be created from a dict of dicts using a list comprehension?,[k for d in list(foo.values()) for k in d]
|
writing a python list of lists to a csv file,"writer.writerow([item[0], item[1], item[2]])"
|
"from a list of strings `my_list`, remove the values that contains numbers.",[x for x in my_list if not any(c.isdigit() for c in x)]
|
plotting time in python with matplotlib,plt.show()
|
change the state of the tkinter `text` widget to read only i.e. `disabled`,text.config(state=DISABLED)
|
how do i transform a multi-level list into a list of strings in python?,"list(map(''.join, a))"
|
horizontal box plots in matplotlib/pandas,plt.show()
|
changing user in python,os.system('sudo -u hadoop bin/hadoop-daemon.sh stop tasktracker')
|
how to make curvilinear plots in matplotlib,"plt.figure(figsize=(8, 8))"
|
"sqlite3, operationalerror: unable to open database file",conn = sqlite3.connect('C:\\users\\guest\\desktop\\example.db')
|
flattening a list of numpy arrays?,np.concatenate(input_list).ravel()
|
write dictionary of lists to a csv file,writer.writerows(zip(*list(d.values())))
|
python pandas plot time-series with gap,df.plot(x=df.index.astype(str))
|
python: find index of minimum item in list of floats,"min(enumerate(a), key=itemgetter(1))[0]"
|
python: importing a file from a parent folder,sys.path.append('..')
|
pandas data frame indexing using loc,"pd.Series([pd.Timestamp('2014-01-03'), 'FRI', 'FIZZ'])"
|
titlecasing a string with exceptions,titlecase('i am a foobar bazbar')
|
how do i set cell values in `np.array()` based on condition?,"np.put(arr, np.where(~np.in1d(arr, valid))[0], 0)"
|
problems with a shared mutable?,"{'tags2': [0, 1], 'cnt2': 0, 'cnt1': 1, 'tags1': [0, 1, 'work']}"
|
python pil: how to draw an ellipse in the middle of an image?,im.show()
|
print two numbers `10` and `20` using string formatting,"""""""{0} {1}"""""".format(10, 20)"
|
call a method of an object with arguments in python,"getattr(o, 'A')(1)"
|
splitting letters from numbers within a string,"re.split('(\\D+)', s)"
|
pandas: mean of columns with the same names,"df.groupby(by=df.columns, axis=1).apply(gf)"
|
convert a string key to int in a dictionary,"d = {int(k): [int(i) for i in v] for k, v in list(d.items())}"
|
python: use regular expression to remove the white space from all lines,"re.sub('(?m)^\\s+', '', 'a\n b\n c')"
|
select rows from a dataframe based on values in a column in pandas,print(df.loc[df['A'] == 'foo'])
|
delete third row in a numpy array `x`,"x = numpy.delete(x, 2, axis=1)"
|
scale image in matplotlib without changing the axis,plt.show()
|
how can i use a 2d array of boolean rows to filter another 2d array?,"data[(np.where(masks)[1]), :]"
|
streaming m3u8 file with opencv,cv2.destroyAllWindows()
|
change the name of a key in dictionary,"dict((d1[key], value) for key, value in list(d.items()))"
|
how to do a less than or equal to filter in django queryset?,User.objects.filter(userprofile__level__gte=0)
|
get output of script `proc`,print(proc.communicate()[0])
|
convert all strings in a list to int,results = [int(i) for i in results]
|
creating a 2d matrix in python,"x = [[None, None, None, None, None, None]] * 6"
|
finding the extent of a matplotlib plot (including ticklabels) in axis coordinates,fig.savefig('so_example.png')
|
how do i insert a list at the front of another list?,a = a[:n] + k + a[n:]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.