text
stringlengths 4
1.08k
|
|---|
How to pass arguments to functions by the click of button in PyQt?,self.button.clicked.connect(self.calluser)
|
Select Children of an Object With ForeignKey in Django?,blog.comment_set.all()
|
Saving a video capture in python with openCV : empty video,cap = cv2.VideoCapture(0)
|
Read a text file with non-ASCII characters in an unknown encoding,"lines = codecs.open('file.txt', 'r', encoding='utf-8').readlines()"
|
Efficiently construct Pandas DataFrame from large list of tuples/rows,"pandas.DataFrame(initialload, columns=list_of_column_names)"
|
how to find the groups of consecutive elements from an array in numpy?,"[array([0]), array([47, 48, 49, 50]), array([97, 98, 99])]"
|
how to initialize multiple columns to existing pandas DataFrame,"pd.concat([df, pd.DataFrame(0, df.index, list('cd'))], axis=1)"
|
How to add group labels for bar charts in matplotlib?,ax.set_xticklabels(x)
|
A good data model for finding a user's favorite stories,"UserFavorite.get_by_name(user_id, parent=a_story)"
|
numpy array: replace nan values with average of columns,"ma.array(a, mask=np.isnan(a)).mean(axis=0)"
|
Python: Sanitize a string for unicode?,uni.encode('utf-8')
|
"String split on new line, tab and some number of spaces",[s.strip().split(': ') for s in data_string.splitlines()]
|
How to make a pandas crosstab with percentages?,"pd.crosstab(df.A, df.B).apply(lambda r: r / len(df), axis=1)"
|
Writing bits to a binary file,"f.write(struct.pack('i', int(bits[::-1], 2)))"
|
Creating a pandas dataframe from a dictionary,pd.DataFrame([record_1])
|
Convert a string to integer with decimal in Python,round(float('23.45678'))
|
Translating an integer into two-byte hexadecimal with Python,"hex(struct.unpack('>H', struct.pack('>h', -200))[0])"
|
How to continuously display python output in a webpage?,app.run(debug=True)
|
Drawing cards from a deck in SciPy with scipy.stats.hypergeom,"scipy.stats.hypergeom.cdf(k, M, n, N)"
|
Most efficient way to implement numpy.in1d for muliple arrays,"[np.nonzero(np.in1d(x, c))[0] for x in [a, b, d, c]]"
|
Inserting JSON into MySQL using Python,"db.execute('INSERT INTO json_col VALUES %s', json_value)"
|
How to do multiple arguments to map function where one remains the same in python?,"map(lambda x: x + 2, [1, 2, 3])"
|
"In python, how to convert a hex ascii string to raw internal binary string?",""""""""""""".join('{0:04b}'.format(int(c, 16)) for c in hex_string)"
|
reading output from pexpect sendline,child.sendline('python -V\r')
|
Binarize a float64 Pandas Dataframe in Python,"pd.DataFrame(np.where(df, 1, 0), df.index, df.columns)"
|
Creating Probability/Frequency Axis Grid (Irregularly Spaced) with Matplotlib,plt.show()
|
Python lambda function,"f = lambda x, y: x + y"
|
decoding json string in python,data = json.load(f)
|
How to index nested lists in Python?,tuple(tup[0] for tup in A)
|
"In Python, if I have a unix timestamp, how do I insert that into a MySQL datetime field?",datetime.fromtimestamp(1268816500)
|
Python pandas plot is a no-show,plt.show()
|
check if string in pandas dataframe column is in list,print(frame[frame['a'].isin(mylist)])
|
flask sqlalchemy query with keyword as variable,"User.query.filter_by(hometown='New York', university='USC')"
|
Splitting a string based on a certain set of words,"result.extend(re.split('_(?:f?or|and)_', s))"
|
How to count the number of letters in a string without the spaces?,sum(c != ' ' for c in word)
|
How to check whether elements appears in the list only once in python?,len(set(a)) == len(a)
|
removing pairs of elements from numpy arrays that are NaN (or another value) in Python,np.isnan(a)
|
how to create similarity matrix in numpy python?,np.cov(x)
|
How can I fill a matplotlib grid?,"plt.plot(x, y, 'o')"
|
How do you get the magnitude of a vector in Numpy?,"np.linalg.norm(x, ord=1)"
|
numpy einsum to get axes permutation,"np.einsum('kij->ijk', M)"
|
How to write Unix end of line characters in Windows using Python,"f = open('file.txt', 'wb')"
|
Python Matplotlib line plot aligned with contour/imshow,plt.show()
|
Rotating a two-dimensional array in Python,"zip([3, 4], [1, 2])"
|
Python: get a dict from a list based on something inside the dict,"new_dict = dict((item['id'], item) for item in initial_list)"
|
Secondary axis with twinx(): how to add to legend?,"ax.plot(np.nan, '-r', label='temp')"
|
Using a global flag for python RegExp compile,"""""""(?s)Your.*regex.*here"""""""
|
"How to decode url to path in python, django","urllib.parse.quote('/static/media/uploads/gallery/Marrakech, Morocco_be3Ij2N.jpg')"
|
Pythonic shorthand for keys in a dictionary?,"{'foo', 'bar', 'baz'}.issubset(list(dct.keys()))"
|
How to print out the indexes in a list with repetitive elements,"[1, 4, 5, 6, 7]"
|
Python matching words with same index in string,"['I am', 'show']"
|
What's the easiest way to convert a list of hex byte strings to a list of hex integers?,b = bytearray('BBA7F69E'.decode('hex'))
|
Data cleanup that requires iterating over pandas.DataFrame 3 rows at a time,"data = pd.DataFrame({'x': [1, 2, 3, 0, 0, 2, 3, 0, 4, 2, 0, 0, 0, 1]})"
|
Python -- Check if object is instance of any class from a certain module,"inspect.getmembers(my_module, inspect.isclass)"
|
How do I print colored output to the terminal in Python?,sys.stdout.write('\x1b[1;31m')
|
How to apply slicing on pandas Series of strings,s.map(lambda x: x[:2])
|
Tornado : support multiple Application on same IOLoop,ioloop.IOLoop.instance().start()
|
How to use different view for django-registration?,"url('^accounts/', include('registration.backends.default.urls')),"
|
How to check if two permutations are symmetric?,"Al = [al1, al2, al3, al4, al5, al6]"
|
How can I group equivalent items together in a Python list?,"[list(g) for k, g in itertools.groupby(iterable)]"
|
How to check if all values in the columns of a numpy matrix are the same?,"np.equal.reduce([False, 0, 1])"
|
How do I write JSON data to a file in Python?,"f.write(json.dumps(data, ensure_ascii=False))"
|
Count the frequency of a recurring list -- inside a list of lists,"Counter(map(tuple, list1))"
|
Get the directory path of absolute file path in Python,os.path.dirname(fullpath)
|
Reverse a string in python without using reversed or [::-1],"list(range(len(strs) - 1, -1, -1))"
|
Write a list to csv file without looping in python,csv_file.writerows(the_list)
|
How do I display add model in tabular format in the Django admin?,"{'fields': (('first_name', 'last_name'), 'address', 'city', 'state')}"
|
How do I configure spacemacs for python 3?,python - -version
|
Ranking of numpy array with possible duplicates,"np.cumsum(np.concatenate(([0], np.bincount(v))))[v]"
|
Python - Flatten a dict of lists into unique values?,"[k for k, g in groupby(sorted(chain.from_iterable(iter(content.values()))))]"
|
concatenate row values for the same index in pandas,df.groupby('A')['expand'].apply(list)
|
Removing non-ascii characters in a csv file,"b.create_from_csv_row(row.encode('ascii', 'ignore'))"
|
Apply a function to the 0-dimension of an ndarray,np.asarray([func(i) for i in arr])
|
Is it possible to renice a subprocess?,Popen(['nice']).communicate()
|
import module from string variable,importlib.import_module('matplotlib.text')
|
How to keep index when using pandas merge,"a.reset_index().merge(b, how='left').set_index('index')"
|
Python: intersection indices numpy array,"numpy.in1d(a, b).nonzero()"
|
Deploy Flask app as windows service,app.run(host='192.168.1.6')
|
Replace a string located between,"re.sub(',(?=[^][]*\\])', '', str)"
|
Transposing part of a pandas dataframe,df.fillna(0)
|
Defining the midpoint of a colormap in matplotlib,ax.set_yticks([])
|
Comparing DNA sequences in Python 3,print(''.join(mismatches))
|
How to transform a tuple to a string of values without comma and parentheses,""""""" """""".join([str(x) for x in t])"
|
python byte string encode and decode,"""""""foo"""""".decode('latin-1')"
|
How to replace all \W (none letters) with exception of '-' (dash) with regular expression?,"re.sub('[^-\\w]', ' ', 'black#white')"
|
How can I get a list of all classes within current module in Python?,current_module = sys.modules[__name__]
|
How to send an email with Gmail as provider using Python?,server.starttls()
|
Python list filtering: remove subsets from list of lists,"[[1, 2, 4, 8], [2, 3, 21], [1, 2, 3, 4, 5, 6, 7]]"
|
How to convert an OrderedDict into a regular dict in python3,"dict(OrderedDict([('method', 'constant'), ('data', '1.225')]))"
|
What's the best way to split a string into fixed length chunks and work with them in Python?,"return (string[0 + i:length + i] for i in range(0, len(string), length))"
|
joining two numpy matrices,"np.hstack([X, Y])"
|
Is there a way to make multiple horizontal boxplots in matplotlib?,plt.figure()
|
How to delete everything after a certain character in a string?,"s = re.match('^.*?\\.zip', s).group(0)"
|
How to pass a Bash variable to Python?,sys.exit(1)
|
Edit the values in a list of dictionaries?,"d.update((k, 'value3') for k, v in d.items() if v == 'value2')"
|
Python parse comma-separated number into int,"int(a.replace(',', ''))"
|
Find 3 letter words,words = [word for word in string.split() if len(word) == 3]
|
Proper way to use **kwargs in Python,"self.val2 = kwargs.get('val2', 'default value')"
|
Equivalent of objects.latest() in App Engine,MyObject.all().order('-time')
|
How to make Fabric ignore offline hosts in the env.hosts list?,env.skip_bad_hosts = True
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.