text
stringlengths 4
1.08k
|
|---|
pandas groupby: count the number of occurences within a time range for each group,df['yes'] = df['WIN'].map(lambda x: 1 if x == 'Yes' else np.nan)
|
select everything but a list of columns from pandas dataframe,df[df.columns.difference(['T1_V6'])]
|
passing columns to rows on python pandas,"df2.columns = ['letter', 'num']"
|
creating a screenshot of a gtk.window,win.show_all()
|
"python: tuples/dictionaries as keys, select, sort",fruits.sort(key=lambda x: x.name.lower())
|
trim whitespace in string `s`,s.strip()
|
shortest way to convert these bytes to int in python?,"struct.unpack('>Q', str)"
|
send data from a textbox into flask?,app.run()
|
get index of the top n values of a list in python,"sorted(list(range(len(a))), key=lambda i: a[i])[-2:]"
|
select the first row grouped per level 0 of dataframe `df`,"df.groupby(level=0, as_index=False).nth(0)"
|
how to use variables in sql statement in python?,"cursor.execute('INSERT INTO table VALUES (%s, %s, %s)', (var1, var2, var3))"
|
"custom arrow style for matplotlib, pyplot.annotate",plt.show()
|
how to execute a command in the terminal from a python script?,os.system(command)
|
plotting 3d polygons in python-matplotlib,plt.show()
|
python - iterating over a subset of a list of tuples,"ones = [(x, y) for x, y in l if y == 1]"
|
typeerror: a float is required,x = float(x)
|
combining two pandas series with changing logic,"x['result'].fillna(False, inplace=True)"
|
how do i plot multiple plots in a single rectangular grid in matplotlib?,plt.show()
|
how can i sum the product of two list items using for loop in python?,"sum(x * y for x, y in list(zip(a, b)))"
|
removing runs from a 2d numpy array,"unset_ones(np.array([0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0]), 3)"
|
convert ascii value 'a' to int,ord('a')
|
print variable `value ` without spaces,"print('Value is ""' + str(value) + '""')"
|
convert a hex string `437c2123 ` according to ascii value.,"""""""437c2123"""""".decode('hex')"
|
convert a binary value '1633837924' to string,"struct.pack('<I', 1633837924)"
|
how to remove duplicates from a dataframe?,"df.sort_values(by=['a', 'b']).groupby(df.a).first()[['b']].reset_index()"
|
python: check if a string contains chinese character?,"re.findall('[\u4e00-\u9fff]+', ipath)"
|
getting the row index for a 2d numpy array when multiple column values are known,np.where((a[0] == 2) & (a[1] == 5))
|
how to set default text for a tkinter entry widget,root.mainloop()
|
python: insert 2d array into mysql table,db.commit()
|
how to find a thread id in python,logging.basicConfig(format='%(threadName)s:%(message)s')
|
write pandas dataframe `df` to the file 'c:\\data\\t.csv' without row names,"df.to_csv('c:\\data\\t.csv', index=False)"
|
how to implement a timeout control for urlllib2.urlopen,"urllib.request.urlopen('http://www.example.com', timeout=5)"
|
how to make a window fullscreen in a secondary display with tkinter?,root.mainloop()
|
python getting a list of value from list of dict,"map(lambda d: d['value'], l)"
|
how can i check if a checkbox is checked in selenium python webdriver?,driver.find_element_by_name('<check_box_name>').is_selected()
|
python split string,"s.split(':', 1)[1]"
|
python: dynamic interval data structure,"print(maximize_nonoverlapping_count([[3, 4], [5, 8], [0, 6], [1, 2]]))"
|
paramiko combine stdout and stderr,ssh.close()
|
python sorting - a list of objects,"sorted(L, key=operator.itemgetter('resultType'))"
|
how can i do a line break (line continuation) in python?,a = '1' + '2' + '3' + '4' + '5'
|
how to create major and minor gridlines with different linestyles in python,plt.show()
|
equivalent to matlab's imagesc in matplotlib?,"ax.imshow(data, extent=[0, 1, 0, 1])"
|
find max length of each column in a list of lists,[max(len(str(x)) for x in line) for line in zip(*foo)]
|
byte array to hex string,"print(''.join(format(x, '02x') for x in array_alpha))"
|
clicking a link using selenium using python,driver.find_element_by_xpath('xpath').click()
|
creating a dictionary from a csv file,"{'Date': ['123', 'abc'], 'Foo': ['456', 'def'], 'Bar': ['789', 'ghi']}"
|
shade 'cells' in polar plot with matplotlib,plt.show()
|
sorting json data by keys value,"sorted(results, key=lambda x: x['year'])"
|
how do you debug url routing in flask?,app.run(debug=True)
|
python: index a dictionary?,"l = [('blue', '5'), ('red', '6'), ('yellow', '8')]"
|
how to unset csrf in modelviewset of django-rest-framework?,"return super(MyModelViewSet, self).dispatch(*args, **kwargs)"
|
how to obtain values of request variables using python and flask,first_name = request.args.get('firstname')
|
convert date strings in pandas dataframe column`df['date']` to pandas timestamps using the format '%d%b%y',"df['date'] = pd.to_datetime(df['date'], format='%d%b%Y')"
|
how can i add a comment to a yaml file in python,f.write('# Data for Class A\n')
|
"if selenium textarea element `foo` is not empty, clear the field",driver.find_element_by_id('foo').clear()
|
how do i add a header to urllib2 opener?,opener.open('http://www.example.com/')
|
how to print a pdf file to stdout using python?,sys.stdout.buffer.write(pdf_file.read())
|
remove duplicate rows from dataframe `df1` and calculate their frequency,"df1.groupby(['key', 'year']).size().reset_index()"
|
python 2.7 - write and read a list from file,my_list = [line.rstrip('\n') for line in f]
|
base64 png in python on windows,"open('icon.png', 'rb')"
|
grab one random item from a database `model` in django/postgresql,model.objects.all().order_by('?')[0]
|
changing file permission in python,"subprocess.call(['chmod', '0444', 'path'])"
|
drop duplicate indexes in a pandas data frame `df`,df[~df.index.duplicated()]
|
round number `h` to nearest integer,h = int(round(h))
|
how to get absolute url in pylons?,"print(url('blog', id=123, qualified=True))"
|
python numpy keep a list of indices of a sorted 2d array,i = a.argsort(axis=None)[::-1]
|
how can i import a string file into a list of lists?,"[[-1, 2, 0], [0, 0, 0], [0, 2, -1], [-1, -2, 0], [0, -2, 2], [0, 1, 0]]"
|
flask : how to architect the project with multiple apps?,app = Flask(__name__)
|
best way to extract subset of key-value pairs from python dictionary object,"{k: bigdict.get(k, None) for k in ('l', 'm', 'n')}"
|
implicit conversions in python,A(1) + A(2)
|
how can i create a simple message box in python?,"ctypes.windll.user32.MessageBoxW(0, 'Your text', 'Your title', 1)"
|
setting the size of the plotting canvas in matplotlib,"plt.savefig('D:\\mpl_logo.png', dpi=dpi, transparent=True)"
|
how can i return http status code 204 from a django view?,return HttpResponse(status=204)
|
how can i add textures to my bars and wedges?,plt.show()
|
convert numpy array to tuple,tuple([tuple(row) for row in myarray])
|
sort list with multiple criteria in python,"sorted(file_list, key=lambda x: map(int, x.split('.')[:-1]))"
|
how to capture the entire string while using 'lookaround' with chars in regex?,"re.findall('(b+ab+)+', mystring)"
|
"check if string 'x' is in list `['x', 'd', 'a', 's', 'd', 's']`","'x' in ['x', 'd', 'a', 's', 'd', 's']"
|
read into a bytearray at an offset?,bytearray('\x00\x00\x00\x07\x08\x00\x00\x00\x00\x00')
|
use upper case letters to print hex value `value`,print('0x%X' % value)
|
how to plot a 3d density map in python with matplotlib,mlab.show()
|
how to select only specific columns from a dataframe with multiindex columns?,"data.loc[:, (list(itertools.product(['one', 'two'], ['a', 'c'])))]"
|
use pyqt4 to create gui that runs python script,sys.exit(app.exec_())
|
how to get one number specific times in an array python,"[4, 5, 5, 6, 6, 6]"
|
convert binary string '010101' to integer,"int('010101', 2)"
|
get only certain fields of related object in django,"Users.objects.filter(id=comment.user_id).values_list('name', 'email')"
|
extract all rows from dataframe `data` where the value of column 'value' is true,data[data['Value'] == True]
|
how can i tell if a file is a descendant of a given directory?,"os.path.commonpath(['/the/dir', os.path.realpath(filename)]) == '/the/dir'"
|
coverting index into multiindex (hierachical index) in pandas,df.index = pd.MultiIndex.from_tuples(df.index.str.split('|').tolist())
|
gnuplot linecolor variable in matplotlib?,"plt.scatter(list(range(len(y))), y, c=z, cmap=cm.hot)"
|
how do i get the user agent with flask?,request.headers.get('User-Agent')
|
parsing date string in python (convert string to date),"datetime.strptime(data[4].partition('T')[0], '%Y-%m-%d').date()"
|
update index after sorting data-frame,df2.reset_index(drop=True)
|
how to make custom legend in matplotlib,plt.show()
|
comparing rows of two pandas dataframes?,"AtB.loc[:2, :2]"
|
python load json file with utf-8 bom header,json.loads(open('sample.json').read().decode('utf-8-sig'))
|
elegant way to convert list to hex string,"hex(int(''.join([str(int(b)) for b in walls]), 2))"
|
python: best way to remove duplicate character from string,""""""""""""".join(ch for ch, _ in itertools.groupby(foo))"
|
check if string `my_string` is empty,"if some_string:
|
pass"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.