text
stringlengths 4
1.08k
|
|---|
Sort a sublist of elements in a list leaving the rest in place,"['X', 'B', 'B1', 'B2', 'B11', 'B21', 'C', 'Q1', 'C11', 'C2', 'B22']"
|
What is the best way of counting distinct values in a Dataframe and group by a different column?,df.groupby('state').DRUNK_DR.value_counts()
|
"How can I convert a character to a integer in Python, and viceversa?",ord('a')
|
python format string thousand separator with spaces,"""""""{:,}"""""".format(1234567890.001).replace(',', ' ')"
|
TypeError: can't use a string pattern on a bytes-like object,print(json.loads(line.decode()))
|
print function in Python,"print(' '.join('%s=%s' % (k, v) for v, k in input))"
|
Pass each element of a list to a function that takes multiple arguments in Python?,zip(*a)
|
How to transform a tuple to a string of values without comma and parentheses,""""""" """""".join(map(str, (34.2424, -64.2344, 76.3534, 45.2344)))"
|
Function that accepts both expanded arguments and tuple,"f(*((1, 4), (2, 5)))"
|
Iterate over matrices in numpy,"np.array(list(itertools.product([0, 1], repeat=n ** 2))).reshape(-1, n, n)"
|
Pandas: join with outer product,demand.ix['Com'].apply(lambda x: x * areas['Com']).stack()
|
Python creating tuple groups in list from another list,"[([1, 2, 3], [-4, -5]), ([3, 2, 4], [-2]), ([5, 6], [-5, -1]), ([1], [])]"
|
python/pandas: how to combine two dataframes into one with hierarchical column index?,"pd.concat(dict(df1=df1, df2=df2), axis=1)"
|
Pandas. Group by field and merge the values in a single row,df.set_index('id').stack().unstack()
|
Python code to create a password encrypted zip file?,zipfile.ZipFile('myarchive.zip').extractall(pwd='P4$$W0rd')
|
Matplotlib - hiding specific ticks on x-axis,plt.show()
|
How can I view a text representation of an lxml element?,"print(etree.tostring(root, pretty_print=True))"
|
How do you sort files numerically?,l.sort(key=alphanum_key)
|
Viewing the content of a Spark Dataframe Column,df.select('zip_code').show()
|
How to create a nested dictionary from a list in Python?,"from functools import reduce
|
lambda l: reduce(lambda x, y: {y: x}, l[::-1], {})"
|
python matplotlib legend shows first entry of a list only,plt.show()
|
Python: converting list of lists to tuples of tuples,tuple_of_tuples = tuple(tuple(x) for x in list_of_lists)
|
How to convert decimal string in python to a number?,float('1.03')
|
Python list sort in descending order,"sorted(timestamp, reverse=True)"
|
"how to change [1,2,3,4] to '1234' using python",""""""""""""".join(map(str, [1, 2, 3, 4]))"
|
How to create a number of empty nested lists in python,lst = [[] for _ in range(a)]
|
How to avoid Python/Pandas creating an index in a saved csv?,"pd.to_csv('your.csv', index=False)"
|
How to parse Django templates for template tags,"""""""{% *url +[^']"""""""
|
How to shift a string to right in python?,l[-1:] + l[:-1]
|
How do you check if a string contains ONLY numbers - python,str.isdigit()
|
Python/Matplotlib - Colorbar Range and Display Values,plt.show()
|
Retrieve matching strings from text file,"re.findall('\\((\\d+)\\)', text)"
|
Is there a way to suppress printing that is done within a unit test?,unittest.main()
|
Get rows that have the same value across its columns in pandas,"df.apply(pd.Series.nunique, axis=1)"
|
How do I add a method with a decorator to a class in python?,MyClass().mymethod()
|
Summarizing dataframe into a dictionary,df.groupby('date')['level'].first().apply(np.ceil).astype(int).to_dict()
|
Multiple substitutions of numbers in string using regex python,"re.sub('(.*)is(.*)want(.*)', '\\g<1>%s\\g<2>%s\\g<3>' % ('was', '12345'), a)"
|
Extracting values from a joined RDDs,list(joined_dataset.values())
|
How to ignore NaN in colorbar?,plt.show()
|
How do I force Django to ignore any caches and reload data?,MyModel.objects.get(id=1).my_field
|
Is it possible to tune parameters with grid search for custom kernels in scikit-learn?,"model.fit(X_train, y_train)"
|
Serialization of a pandas DataFrame,df.to_pickle(file_name)
|
matplotlib axis label format,"ax1.xaxis.get_major_formatter().set_powerlimits((0, 1))"
|
Python code for counting number of zero crossings in an array,"sum(1 for i in range(1, len(a)) if a[i - 1] * a[i] < 0)"
|
Pandas to_csv call is prepending a comma,df.to_csv('c:\\data\\t.csv')
|
Hide axis values in matplotlib,plt.show()
|
How to decrypt unsalted openssl compatible blowfish CBC/PKCS5Padding password in python?,"cipher.decrypt(ciphertext).replace('\x08', '')"
|
numpy select fixed amount of values among duplicate values in array,"array([1, 2, 2, 3, 3])"
|
how to extract a substring from inside a string in Python?,"print(re.search('AAA(.*?)ZZZ', 'gfgfdAAA1234ZZZuijjk').group(1))"
|
Python Inverse of a Matrix,"A = matrix([[1, 2, 3], [11, 12, 13], [21, 22, 23]])"
|
remove redundant ticker in x-axis shared plot in matplotlib,plt.show()
|
Removing items from unnamed lists in Python,[x for x in something_iterable if x != 'item']
|
Python BeautifulSoup Extract specific URLs,"soup.select('a[href^=""http://www.iwashere.com/""]')"
|
Sort a list by the number of occurrences of the elements in the list,"sorted(A, key=key_function)"
|
How to convert numpy datetime64 into datetime,datetime.datetime.utcfromtimestamp(x.astype('O') / 1000000000.0)
|
How to do a git reset --hard using gitPython?,"repo.git.reset('--hard', 'origin/master')"
|
"How to make python window run as ""Always On Top""?",gtk.Window.set_keep_above
|
How to pivot data in a csv file?,"csv.writer(open('output.csv', 'wb')).writerows(a)"
|
How do I display real-time graphs in a simple UI for a python program?,plt.show()
|
Python using getattr to call function with variable parameters,"getattr(foo, bar)(*params)"
|
Python failing to encode bad unicode to ascii,"s.decode('ascii', 'ignore')"
|
Grouping Python dictionary keys as a list and create a new dictionary with this list as a value,"{k: list(v) for k, v in groupby(sorted(d.items()), key=itemgetter(0))}"
|
Fastest way to filter a numpy array by a set of values,"a[np.in1d(a[:, (2)], list(b))]"
|
python converting datetime to be used in os.utime,settime = time.mktime(ftime.timetuple())
|
Print the key of the max value in a dictionary the pythonic way,"print(max(list(d.keys()), key=lambda x: d[x]))"
|
finding the derivative of a polynomial,"deriv_poly = [(poly[i] * i) for i in range(1, len(poly))]"
|
How to use python numpy.savetxt to write strings and float number to an ASCII file?,"num.savetxt('test.txt', DAT, delimiter=' ', fmt='%s')"
|
How to perform element-wise multiplication of two lists in Python?,ab = [(a[i] * b[i]) for i in range(len(a))]
|
Join float list into space-separated string in Python,"print(' '.join(map(str, a)))"
|
How to convert hex string to integer in Python?,"y = str(int(x, 16))"
|
Joining pairs of elements of a list - Python,"[(i + j) for i, j in zip(x[::2], x[1::2])]"
|
How do I add space between two variables after a print in Python,print(str(count) + ' ' + str(conv))
|
Running Cumulative sum of 1d NumPy Array,y = np.cumsum(x)
|
Print the key of the max value in a dictionary the pythonic way,"print(max(d, key=d.get))"
|
Convert a string to datetime object in python,print(dateobj.strftime('%Y-%m-%d'))
|
How to optimize multiprocessing in Python,multiprocessing.Process.__init__(self)
|
How to apply a function to a column in Pandas depending on the value in another column?,"df['Words'] = df.apply(lambda row: func(row, 'Match Conflict'), axis=1)"
|
Setting the window to a fixed size with Tkinter,root.mainloop()
|
How do I hide a sub-menu in QMenu,self.submenu2.menuAction().setVisible(False)
|
Sum of outer product of corresponding lists in two arrays - NumPy,"np.einsum('ik,il->i', x, e)"
|
Find Average of Every Three Columns in Pandas dataframe,"df.resample('Q', axis=1).mean()"
|
Compare multiple columns in numpy array,"y[:, (cols)].sum()"
|
"Python, Encoding output to UTF-8",content.decode('utf8')
|
understanding list comprehension for flattening list of lists in python,[(item for sublist in list_of_lists) for item in sublist]
|
How to remove an element from a set?,[(x.discard('') or x) for x in test]
|
Python: How to Sort List by Last Character of String,"sorted(s, key=lambda x: int(re.search('\\d+$', x).group()))"
|
Python - Convert dictionary into list with length based on values,[i for i in d for j in range(d[i])]
|
Write dictionary of lists to a CSV file,writer.writerows(zip(*list(d.values())))
|
How to sort a list by checking values in a sublist in python?,"sorted(L, key=itemgetter(1), reverse=True)"
|
How to iterate through rows of a dataframe and check whether value in a column row is NaN,df[df['Column2'].notnull()]
|
How to create a user in Django?,"return render(request, 'home.html')"
|
Python spliting a list based on a delimiter word,"[['A'], ['WORD', 'B', 'C'], ['WORD', 'D']]"
|
How can I allow django admin to set a field to NULL?,"super(MyModel, self).save(*args, **kwargs)"
|
Remove one column for a numpy array,"b = a[:, :-1, :]"
|
How to run Spark Java code in Airflow?,"sys.path.append(os.path.join(os.environ['SPARK_HOME'], 'bin'))"
|
In Python How can I declare a Dynamic Array,"lst = [1, 2, 3]"
|
Python List of Dictionaries[int : tuple] Sum,sum(v[1] for d in myList for v in d.values())
|
"Dynamically import a method in a file, from a string",importlib.import_module('abc.def.ghi.jkl.myfile.mymethod')
|
changing figure size with subplots,"f, axs = plt.subplots(2, 2, figsize=(15, 15))"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.