text stringlengths 4 1.08k |
|---|
Convert a row in pandas into list,"df.apply(lambda x: x.tolist(), axis=1)" |
Convert a 1D array to a 2D array in numpy,"B = np.reshape(A, (-1, 2))" |
Flask - How to make an app externally visible through a router?,"app.run(host='192.168.0.58', port=9000, debug=False)" |
Stdout encoding in python,print('\xc5\xc4\xd6'.encode('UTF8')) |
Best way to get the nth element of each tuple from a list of tuples in Python,[x[0] for x in G] |
Regular expression matching all but a string,"re.findall('-(?!aa-|bb-)([^-]+)', string)" |
Regular expression matching all but a string,"re.findall('-(?!aa|bb)([^-]+)', string)" |
Removing entries from a dictionary based on values,"{k: v for k, v in list(hand.items()) if v}" |
Removing entries from a dictionary based on values,"dict((k, v) for k, v in hand.items() if v)" |
Python sorting - A list of objects,"sorted(L, key=operator.itemgetter('resultType'))" |
Python sorting - A list of objects,s.sort(key=operator.attrgetter('resultType')) |
Python sorting - A list of objects,somelist.sort(key=lambda x: x.resultType) |
pandas joining multiple dataframes on columns,"df1.merge(df2, on='name').merge(df3, on='name')" |
random Decimal in python,decimal.Decimal(random.randrange(10000)) / 100 |
list all files of a directory,"onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]" |
list all files of a directory,print(glob.glob('/home/adam/*.txt')) |
list all files of a directory,os.listdir('somedirectory') |
psycopg2: insert multiple rows with one query,"cur.executemany('INSERT INTO table VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)', tup)" |
get key by value in dictionary with same value in python?,print([key for key in d if d[key] == 1]) |
get key by value in dictionary with same value in python?,"print([key for key, value in d.items() if value == 1])" |
get key by value in dictionary with same value in python?,"print([key for key, value in list(d.items()) if value == 1])" |
What is the best way to create a string array in python?,strs = ['' for x in range(size)] |
Remove duplicate dict in list in Python,[dict(t) for t in set([tuple(d.items()) for d in l])] |
How to set the timezone in Django?,TIME_ZONE = 'Europe/Istanbul' |
Appending to list in Python dictionary,"dates_dict.setdefault(key, []).append(date)" |
How to do this GROUP BY query in Django's ORM with annotate and aggregate,Article.objects.values('pub_date').annotate(article_count=Count('title')) |
How to clear Tkinter Canvas?,canvas.delete('all') |
How to add a specific number of characters to the end of string in Pandas?,"s = pd.Series(['A', 'B', 'A1R', 'B2', 'AABB4'])" |
How do I translate a ISO 8601 datetime string into a Python datetime object?,"datetime.datetime.strptime('2007-03-04T21:08:12', '%Y-%m-%dT%H:%M:%S')" |
How to sort a list according to another list?,a.sort(key=lambda x: b.index(x[0])) |
How to sort a list according to another list?,a.sort(key=lambda x_y: b.index(x_y[0])) |
Matplotlib - How to plot a high resolution graph?,plt.savefig('filename.png') |
Matplotlib - How to plot a high resolution graph?,"plt.savefig('filename.png', dpi=300)" |
How to get output of exe in python script?,p1.communicate()[0] |
How to get output of exe in python script?,"output = subprocess.Popen(['mycmd', 'myarg'], stdout=PIPE).communicate()[0]" |
Using BeautifulSoup to search html for string,soup.body.findAll(text='Python') |
Using BeautifulSoup to search html for string,soup.body.findAll(text='Python Jobs') |
Python: sorting items in a dictionary by a part of a key?,"sorted(list(d.items()), key=lambda name_num: (name_num[0].rsplit(None, 1)[0], name_num[1]))" |
Find non-common elements in lists,"set([1, 2, 3]) ^ set([3, 4, 5])" |
retrieving list items from request.POST in django/python,request.POST.getlist('pass_id') |
How do I remove dicts from a list with duplicate fields in python?,"list(dict((x['id'], x) for x in L).values())" |
Merge Columns within a DataFrame that have the Same Name,"df.groupby(df.columns, axis=1).sum()" |
python dict comprehension with two ranges,"dict(zip(list(range(1, 5)), list(range(7, 11))))" |
How to turn a boolean array into index array in numpy,numpy.where(mask) |
case insensitive string comparison,"if (string1.lower() == string2.lower()): |
pass" |
case insensitive string comparison,(string1.lower() == string2.lower()) |
case insensitive string comparison,(first.lower() == second.lower()) |
case insensitive string comparison,(first.upper() == second.upper()) |
Taking the results of a bash command and using it in python,"os.system(""awk '{print $10, $11}' test.txt > test2.txt"")" |
How to remove multiple indexes from a list at the same time?,del my_list[2:6] |
How to convert a string to its Base-10 representation?,"int(s.encode('hex'), 16)" |
Python regular expression with codons,"re.findall('TAA(?:[ATGC]{3})+?TAA', seq)" |
Sorting a set of values,"sorted(s, key=float)" |
convert an int to a hex string,hex(65) |
Simple way to append a pandas series with same index,a.append(b).reset_index(drop=True) |
Simple way to append a pandas series with same index,"pd.concat([a, b], ignore_index=True)" |
"In Python, is there a concise way to use a list comprehension with multiple iterators?","[(i, j) for i in range(1, 3) for j in range(1, 5)]" |
sorting values of python dict using sorted builtin function,"sorted(iter(mydict.items()), key=itemgetter(1), reverse=True)" |
How can I select 'last business day of the month' in Pandas?,"pd.date_range('1/1/2014', periods=12, freq='BM')" |
How do I disable the security certificate check in Python requests,"requests.get('https://kennethreitz.com', verify=False)" |
"dropping a row in pandas with dates indexes, python",df.ix[:-1] |
string contains substring,"if ('blah' not in somestring): |
pass" |
string contains substring,"if (needle in haystack): |
pass" |
string contains substring,string.find('substring') |
Extract first and last row of a dataframe in pandas,"pd.concat([df.head(1), df.tail(1)])" |
Django - Filter queryset by CharField value length,MyModel.objects.extra(where=['CHAR_LENGTH(text) > 254']) |
Django - Filter queryset by CharField value length,MyModel.objects.filter(text__regex='^.{254}.*') |
Best way to count the number of rows with missing values in a pandas DataFrame,"sum(df.apply(lambda x: sum(x.isnull().values), axis=1) > 0)" |
Sorting while preserving order in python,"sorted(enumerate(a), key=lambda x: x[1])" |
How to set the font size of a Canvas' text item?,"canvas.create_text(x, y, font=('Purisa', 12), text=k)" |
Python: How to use a list comprehension here?,[y['baz'] for x in foos for y in x['bar']] |
pandas read csv with extra commas in column,"df = pd.read_csv('comma.csv', quotechar=""'"")" |
avoiding regex in pandas str.replace,"df['a'] = df['a'].str.replace('in.', ' in. ')" |
Finding the index of elements based on a condition using python list comprehension,[i for i in range(len(a)) if a[i] > 2] |
check if a variable exists,('myVar' in locals()) |
check if a variable exists,('myVar' in globals()) |
check if a variable exists,"hasattr(obj, 'attr_name')" |
check if a variable exists,"if ('myVar' in locals()): |
pass" |
check if a variable exists,"if ('myVar' in globals()): |
pass" |
Python lambda function,"lambda x, y: x + y" |
What's the shortest way to count the number of items in a generator/iterator?,sum(1 for i in it) |
how to get tuples from lists using list comprehension in python,"[(x, lst2[i]) for i, x in enumerate(lst)]" |
how to get tuples from lists using list comprehension in python,"[(i, j) for i, j in zip(lst, lst2)]" |
how to get tuples from lists using list comprehension in python,"[(lst[i], lst2[i]) for i in range(len(lst))]" |
How do I convert a hex triplet to an RGB tuple and back?,"struct.unpack('BBB', rgbstr.decode('hex'))" |
Check if something is not in a list,"(3 not in [2, 3, 4])" |
Check if something is not in a list,"((2, 3) not in [(2, 3), (5, 6), (9, 1)])" |
Check if something is not in a list,"((2, 3) not in [(2, 7), (7, 3), 'hi'])" |
Check if something is not in a list,"(3 not in [4, 5, 6])" |
"Create new list by taking first item from first list, and last item from second list","[value for pair in zip(a, b[::-1]) for value in pair]" |
Remove one column for a numpy array,"b = np.delete(a, -1, 1)" |
"Python mySQL Update, Working but not updating table",dbb.commit() |
How do I join two dataframes based on values in selected columns?,"pd.merge(a, b, on=['A', 'B'], how='outer')" |
How to change QPushButton text and background color,setStyleSheet('QPushButton {background-color: #A3C1DA; color: red;}') |
Finding the average of a list,sum(l) / float(len(l)) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.