text
stringlengths 4
1.08k
|
|---|
separate numbers and characters in string '20m10000n80m',"re.findall('([0-9]+)([A-Z])', '20M10000N80M')"
|
working with nan values in matplotlib,plt.show()
|
overriding initial value in modelform,"super(ArtefactForm, self).__init__(*args, **kwargs)"
|
find and replace values in xml using python,tree.find('.//enddate').text = '1/1/2011'
|
coverting index into multiindex (hierachical index) in pandas,"df.set_index(['e-mail', 'date'])"
|
sort a part of a list in place,a[i:j] = sorted(a[i:j])
|
string formatting without index in python2.6,"'%s %s' % ('foo', 'bar')"
|
most pythonic way to create many new columns in pandas,"df = pd.DataFrame(np.random.random((1000, 100)))"
|
how to change the table's fontsize with matplotlib.pyplot?,plt.show()
|
parse 4th capital letter of line in python?,""""""""""""".join(re.findall('[A-Z][^A-Z]*', s)[3:])"
|
append 3 lists in one list,[[] for i in range(3)]
|
trouble with duplicate lines of logs in log file,hdl = logging.FileHandler('hits.log')
|
inverse of a matrix using numpy,"numpy.array([[0, 1, 0], [0, 0, 0], [0, 0, 0]])"
|
convert a list to a dictionary in python,"dict(x[i:i + 2] for i in range(0, len(x), 2))"
|
"split string in column 'stats' by ',' into separate columns in dataframe `df`","df['stats'].str[1:-1].str.split(',').apply(pd.Series).astype(float)"
|
convert a pandas dataframe to a dictionary,"df.set_index('ID', drop=True, inplace=True)"
|
how can a pandas merge preserve order?,"x.merge(x.merge(y, how='left', on='state', sort=False))"
|
django get latest entry from database,Status.objects.order_by('id')[0]
|
retrieve matching strings from text file,"re.findall('\\((\\d+)\\)', text)"
|
python: check if one dictionary is a subset of another larger dictionary,all(item in list(superset.items()) for item in list(subset.items()))
|
check whether a path is valid in python without creating a file at the path's target,"open(filename, 'r')"
|
do a boolean check if a string `lestring` contains any of the items in list `lelist`,any(e in lestring for e in lelist)
|
how can i convert a binary to a float number,"struct.unpack('d', struct.pack('Q', int(s2, 0)))[0]"
|
insert 0s into 2d array,"array([[-1, -2, -1, 2], [0, -1, 0, 3], [1, 0, 1, 4]])"
|
select a substring of `s` beginning at `beginning` of length `length`,s = s[beginning:(beginning + LENGTH)]
|
how to send file as stream from python to a c library,main()
|
pandas dataframe group year index by decade,df.groupby(df.index.year).sum().head()
|
django aggregation by the name of day,MyMode.objects.values('day').annotate(Sum('visits')).filter(day__week_day=1)
|
create a set containing all keys names from list of dictionaries `lod`,set([i for s in [list(d.keys()) for d in LoD] for i in s])
|
how to overwrite a file in python?,"open('some_path', 'r+')"
|
how do you plot a vertical line on a time series plot in pandas?,"ax.axvline(x, color='k', linestyle='--')"
|
adding a string in front of a string for each item in a list in python,n = [(i if i.startswith('h') else 'http' + i) for i in n]
|
python using custom color in plot,"ax.plot(x, mpt1, color='dbz53', label='53 dBz')"
|
convert escaped utf string to utf string in `your string`,print('your string'.decode('string_escape'))
|
check if date `yourdatetime` is equal to today's date,yourdatetime.date() == datetime.today().date()
|
converting dataframe into a list,df.values.T.tolist()
|
sort pandas dataframe by date,df.sort_values(by='Date')
|
compile visual studio project `project.sln` from the command line through python,os.system('msbuild project.sln /p:Configuration=Debug')
|
how do i generate a png file w/ selenium/phantomjs from a string?,driver.quit()
|
how to convert a timedelta object into a datetime object,today + datetime.timedelta(days=1)
|
normalizing colors in matplotlib,plt.show()
|
get a list of keys of dictionary `things` sorted by the value of nested dictionary key 'weight',"sorted(list(things.keys()), key=lambda x: things[x]['weight'], reverse=True)"
|
how to count values in a certain range in a numpy array?,((25 < a) & (a < 100)).sum()
|
how do i print colored output to the terminal in python?,sys.stdout.write('\x1b[1;31m')
|
insert item into case-insensitive sorted list in python,"['a', 'A', 'b', 'B', 'c', 'C', 'd', 'D', 'e', 'E']"
|
pandas: union duplicate strings,"df.groupby(['ID', 'url'])['active_seconds'].cumsum()"
|
remove newline in string `s`,s.strip()
|
round number `x` to nearest integer,int(round(x))
|
"how to get value on a certain index, in a python list?","dictionary = dict(zip(List[0::2], List[1::2]))"
|
matplotlib fill beetwen multiple lines,plt.show()
|
fastest way to sort each row in a pandas dataframe,"df.sort(axis=1, ascending=False)"
|
how to use gevents with falcon?,server.serve_forever()
|
where do you store the variables in jinja?,"return render_template('hello.html', name=name)"
|
split pandas dataframe column based on number of digits,df.value.astype(str).apply(list).apply(pd.Series).astype(int)
|
how do i capture sigint in python?,sys.exit(0)
|
how to get pandas.read_csv() to infer datetime and timedelta types from csv file columns?,df['timedelta'] = pd.to_timedelta(df['timedelta'])
|
tuple to string,tst2 = str(tst)
|
how to match beginning of string or character in python,"re.findall('[a]', 'abcd')"
|
how to convert nested list of lists into a list of tuples in python 3.3?,"list(map(tuple, [['tom', 'cat'], ['jerry', 'mouse'], ['spark', 'dog']]))"
|
python: convert a list of python dictionaries to an array of json objects,json.dumps([dict(mpn=pn) for pn in lst])
|
"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))"
|
remove one column for a numpy array,"b = a[:, :-1, :]"
|
print a celsius symbol on x axis of a plot `ax`,ax.set_xlabel('Temperature (\u2103)')
|
writing items in list `thelist` to file `thefile`,"for item in thelist:
|
thefile.write(('%s\n' % item))"
|
removing starting spaces in python?,"re.sub('^[^a]*', '')"
|
defining a discrete colormap for imshow in matplotlib,plt.show()
|
removing key values pairs from a list of dictionaries,"[{k: v for k, v in d.items() if k != 'mykey1'} for d in mylist]"
|
filling array with zeros in numpy,"np.zeros((4, 3, 2))"
|
how to visualize scalar 2d data with matplotlib?,plt.show()
|
set colorbar range in matplotlib,plt.colorbar()
|
pandas - data frame - reshaping values in data frame,"df.set_index(['row_id', 'Game_ID']).unstack(level=0).sortlevel(level=1, axis=1)"
|
how to find and replace nth occurence of word in a sentence using python regular expression?,"re.sub('^((.*?cat.*?){1})cat', '\\1Bull', s)"
|
sort numpy matrix row values in ascending order,"numpy.sort(arr, axis=0)"
|
matplotlib: how to force integer tick labels?,plt.show()
|
pythonic way to access the shifted version of numpy array?,"np.roll(a, 1)"
|
encode each value to 'utf8' in the list `employeelist`,[x.encode('UTF8') for x in EmployeeList]
|
how to write binary data in stdout in python 3?,sys.stdout.buffer.write('some binary data')
|
list of objects to json with python,"json_string = json.dumps(list_name, default=obj_dict)"
|
check if string `the_string` contains any upper or lower-case ascii letters,"re.search('[a-zA-Z]', the_string)"
|
python pandas : how to skip columns when reading a file?,"a = pd.read_table('file', header=None, sep=' ', usecols=list(range(8)))"
|
convert a string `s` containing hex bytes to a hex string,s.decode('hex')
|
python creating a dictionary of lists,"dict((i, list(range(int(i), int(i) + 2))) for i in ['1', '2'])"
|
parse string '01-jan-1995' into a datetime object using format '%d-%b-%y',"datetime.datetime.strptime('01-Jan-1995', '%d-%b-%Y')"
|
sort a list by multiple attributes?,"s = sorted(s, key=lambda x: (x[1], x[2]))"
|
add a tuple to a specific cell of a pandas dataframe,tempDF['newTuple'] = 's'
|
matplotlib - label each bin,plt.show()
|
python csv: remove quotes from value,"csv.reader(upload_file, delimiter=',', quotechar='""')"
|
is there a way to get a list of column names in sqlite?,names = [description[0] for description in cursor.description]
|
python: how to convert a string containing hex bytes to a hex string,binascii.a2b_hex(s)
|
make a 60 seconds time delay,time.sleep(60)
|
can a python script execute a function inside a bash script?,subprocess.call('test.sh otherfunc')
|
how to remove square bracket from pandas dataframe,df['value'] = df['value'].str.strip('[]')
|
how to check if all elements of a list matches a condition?,any(item[2] == 0 for item in items)
|
using beautifulsoup to select div blocks within html,"soup.find_all('div', class_='crBlock ')"
|
how to authenticate a public key with certificate authority using python?,"requests.get(url, verify='/path/to/cert.pem')"
|
how to plot time series in python,plt.show()
|
how to disable input to a text widget but allow programatic input?,text_widget.configure(state='disabled')
|
"convert a datetime object `my_datetime` into readable format `%b %d, %y`","my_datetime.strftime('%B %d, %Y')"
|
sort list `student_tuples` by second element of each tuple in ascending and third element of each tuple in descending,"print(sorted(student_tuples, key=lambda t: (-t[2], t[0])))"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.