text
stringlengths
4
1.08k
Python MySQLdb TypeError: not all arguments converted during string formatting,"cur.execute(""SELECT * FROM records WHERE email LIKE '%s'"", [search])"
How to check if type of a variable is string?,"isinstance(s, str)"
Finding index of the same elements in a list,"[index for index, letter in enumerate(word) if letter == 'e']"
Finding superstrings in a set of strings in python,"['136 139 277 24', '246']"
Trying to find majority element in a list,"find_majority([1, 2, 3, 4, 3, 3, 2, 4, 5, 6, 1, 2, 3, 4, 5, 1, 2, 3, 4, 6, 5])"
Indexing numpy array with another numpy array,a[tuple(b)]
How to update a histogram when a slider is used?,plt.show()
Slicing a multidimensional list,[[[x[0]] for x in listD[i]] for i in range(len(listD))]
How do you extract a column from a multi-dimensional array?,[row[0] for row in a]
How to select parent based on the child in lxml?,"t.xpath('//a[@href = ""http://exact url""]')[0]"
Lack of randomness in numpy.random,"x, y = np.random.rand(2, 100) * 20"
How to convert hex string to integer in Python?,"y = str(int(x, 16))"
Sort a list by multiple attributes?,"s.sort(key=operator.itemgetter(1, 2))"
How to hide Firefox window (Selenium WebDriver)?,driver = webdriver.Firefox()
How can I multiply all items in a list together with Python?,"from functools import reduce
reduce(lambda x, y: x * y, [1, 2, 3, 4, 5, 6])"
Select rows from a DataFrame based on values in a column in pandas,df.loc[df['column_name'] != some_value]
How can I get all the plain text from a website with Scrapy?,""""""""""""".join(sel.select('//body//text()').extract()).strip()"
How to add a scrollbar to a window with tkinter?,root.mainloop()
Creating a list of objects in Python,instancelist = [MyClass() for i in range(29)]
How to speed up the code - searching through a dataframe takes hours,df.head()
How to sort a dataFrame in python pandas by two or more columns?,"df.sort(['a', 'b'], ascending=[True, False])"
Python Pandas : group by in group by and average?,df.groupby(['cluster']).mean()
Python check if any element in a list is a key in dictionary,"any([True, False, False])"
"In python 2.4, how can I execute external commands with csh instead of bash?",os.system('tcsh your_own_script')
How to remove multiple values from an array at once,"np.delete(1, 1)"
Matplotlib: How to force integer tick labels?,ax.xaxis.set_major_locator(MaxNLocator(integer=True))
"How to create datetime object from ""16SEP2012"" in python","datetime.datetime.strptime('16Sep2012', '%d%b%Y')"
"In Python, how do I convert all of the items in a list to floats?",[float(i) for i in lst]
"python - Finding the user's ""Downloads"" folder","return os.path.join(home, 'Downloads')"
best way to extract subset of key-value pairs from python dictionary object,"dict((k, bigdict[k]) for k in ('l', 'm', 'n'))"
Write multiple numpy arrays to file,"np.savetxt('test.txt', data)"
Parsing string containing Unicode character names,'M\\N{AMPERSAND}M\\N{APOSTROPHE}s'.decode('unicode-escape')
iterate through unicode strings and compare with unicode in python dictionary,'\u50b5'.encode('utf-8')
Python. Convert escaped utf string to utf-string,print('your string'.decode('string_escape'))
How can I split this comma-delimited string in Python?,"mystring.split(',')"
How to get rid of grid lines when plotting with Seaborn + Pandas with secondary_y,"sns.set_style('whitegrid', {'axes.grid': False})"
How to group by date range,"df.groupby(['employer_key', 'account_id'])"
Slicing URL with Python,url.split('&')
How does this function to remove duplicate characters from a string in python work?,print(' '.join(OrderedDict.fromkeys(s)))
How do you remove the column name row from a pandas DataFrame?,"df.to_csv('filename.csv', header=False)"
Moving x-axis to the top of a plot in matplotlib,ax.xaxis.set_ticks_position('top')
Python: Lambda function in List Comprehensions,[(x * x) for x in range(10)]
deleting rows in numpy array,"x = numpy.delete(x, 0, axis=0)"
how to access dictionary element in django template?,"choices = {'key1': 'val1', 'key2': 'val2'}"
How to remove all characters before a specific character in Python?,"re.sub('.*I', 'I', stri)"
Python How to get every first element in 2 Dimensional List,[x[0] for x in a]
Customize x-axis in matplotlib,plt.show()
Python regular expression for Beautiful Soup,[div['class'] for div in soup.find_all('div')]
Create a list of integers with duplicate values in Python,"['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c', 'd', 'd', 'd', 'e', 'e', 'e']"
Python Finding Index of Maximum in List,"max(enumerate(a), key=lambda x: x[1])[0]"
How do I print the content of a .txt file in Python?,"f = open('example.txt', 'r')"
Python logging typeerror,logging.info('test')
Combine two Pandas dataframes with the same index,"pd.merge(df1, df2, left_index=True, right_index=True, how='outer')"
How Do I Bold only part of a string in an excel cell with python,ws.Range('A1').Characters
Django - Filter queryset by CharField value length,MyModel.objects.extra(where=['CHAR_LENGTH(text) > 254'])
Python: Finding average of a nested list,a = [(sum(x) / len(x)) for x in zip(*a)]
Python: store many regex matches in tuple?,"['home', 'about', 'music', 'photos', 'stuff', 'contact']"
Creating a Unicode XML from scratch with Python 3.2,"tree.write('c.xml', encoding='utf-8')"
Python: How to add three text files into one variable and then split it into a list,"msglist = [hextotal[i:i + 4096] for i in range(0, len(hextotal), 4096)]"
Find Max in Nested Dictionary,"max(d, key=lambda x: d[x]['count'])"
How to set window size using phantomjs and selenium webdriver in python,"driver.set_window_size(1400, 1000)"
Python cant get full path name of file,"os.path.realpath(os.path.join(root, name))"
python - convert binary data to utf-8,data.decode('latin-1').encode('utf-8')
UTF in Python Regex,re.compile('\u2013')
Execute terminal command from python in new terminal window?,"subprocess.call('start /wait python bb.py', shell=True)"
how to convert a datetime string back to datetime object?,"datetime.strptime('2010-11-13 10:33:54.227806', '%Y-%m-%d %H:%M:%S.%f')"
Python Selenium: Find object attributes using xpath,"browser.find_elements_by_xpath(""//*[@type='submit']"").get_attribute('value')"
removing duplicates of a list of sets,list(set(frozenset(item) for item in L))
What does a for loop within a list do in Python?,myList = [i for i in range(10) if i % 2 == 0]
How to Customize the time format for Python logging?,formatter = logging.Formatter('%(asctime)s;%(levelname)s;%(message)s')
Append several variables to a list in Python,"vol.extend((volumeA, volumeB, volumeC))"
PUT Request to REST API using Python,"response = requests.put(url, data=json.dumps(data), headers=headers)"
pandas: combine two columns in a DataFrame,"pandas.concat([df['foo'].dropna(), df['bar'].dropna()]).reindex_like(df)"
How to reverse query objects for multiple levels in django?,Level4.objects.filter(level3__level2__level1=my_level1_object)
Indexing a pandas dataframe by integer,df2 = df.reset_index()
How to scale Seaborn's y-axis with a bar plot?,plt.show()
"Python, Matplotlib, subplot: How to set the axis range?","pylab.ylim([0, 1000])"
Pandas: Counting unique values in a dataframe,d.stack().groupby(level=0).apply(pd.Series.value_counts).unstack().fillna(0)
Parsing XML with namespace in Python via 'ElementTree',root.findall('{http://www.w3.org/2002/07/owl#}Class')
Plotting histogram or scatter plot with matplotlib,plt.show()
Dropping a single (sub-) column from a MultiIndex,"df.drop('a', level=1, axis=1)"
Slicing a multidimensional list,[[x[0] for x in listD[3]]]
How do I use a relative path in a Python module when the CWD has changed?,package_directory = os.path.dirname(os.path.abspath(__file__))
How to sort a dataFrame in python pandas by two or more columns?,"df1.sort(['a', 'b'], ascending=[True, False], inplace=True)"
print variable and a string in python,print('I have: {0.price}'.format(card))
format strings and named arguments in Python,"""""""{1} {ham} {0} {foo} {1}"""""".format(10, 20, foo='bar', ham='spam')"
Python - Subprocess - How to call a Piped command in Windows?,"subprocess.call(['ECHO', 'Ni'], shell=True)"
Check for a valid domain name in a string?,"""""""[a-zA-Z\\d-]{,63}(\\.[a-zA-Z\\d-]{,63})*"""""""
How to check if all elements of a list matches a condition?,any(item[2] == 0 for item in items)
get keys correspond to a value in dictionary,"dict((v, k) for k, v in map.items())"
how to create a group ID based on 5 minutes interval in pandas timeseries?,df.groupby(pd.TimeGrouper('5Min'))['val'].apply(lambda x: len(x) > 3)
How to find the difference between 3 lists that may have duplicate numbers,"Counter([1, 2, 2, 2, 3]) - Counter([1, 2])"
How do I disable the security certificate check in Python requests,"requests.get('https://kennethreitz.com', verify=False)"
Compare Python Pandas DataFrames for matching rows,"pd.merge(df1, df2, on=['A', 'B', 'C', 'D'], how='inner')"
"In Python, how can I turn this format into a unix timestamp?","time.strptime('Mon Jul 09 09:20:28 +0000 2012', '%a %b %d %H:%M:%S +0000 %Y')"
convert list into string with spaces in python,""""""" """""".join(my_list)"
Getting 'str' object has no attribute 'get' in Django,request.GET.get('id')
How to print variables without spaces between values,"print('Value is ""{}""'.format(value))"
Splitting a string based on a certain set of words,"[re.split('_(?:f?or|and)_', s) for s in l]"