text stringlengths 4 1.08k |
|---|
Dynamically changing log level in python without restarting the application,logging.getLogger().setLevel(logging.DEBUG) |
How to strip white spaces in Python without using a string method?,""""""""""""".join(str(x) for x in range(1, N + 1))" |
Python date string formatting,"""""""{0.month}/{0.day}/{0.year}"""""".format(my_date)" |
How to round integers in python,"print(round(1123.456789, -1))" |
How to group by multiple keys in spark?,"[('id1, pd1', '5.0, 7.5, 8.1'), ('id2, pd2', '6.0')]" |
Python regular expression match whole word,"re.search('\\bis\\b', your_string)" |
Sorting while preserving order in python,"sorted(enumerate(a), key=lambda x: x[1])" |
python split string based on regular expression,"re.findall('\\S+', str1)" |
How to find row of 2d array in 3d numpy array,"array([[True, True], [False, False], [False, False], [True, True]], dtype=bool)" |
How do I create a LIST of unique random numbers?,"random.sample(list(range(100)), 10)" |
getting string between 2 characters in python,"re.findall('\\$(.*?)\\$', '$sin (x)$ is an function of x')" |
Finding the largest delta between two integers in a list in python,"max(abs(x - y) for x, y in zip(values[1:], values[:-1]))" |
Converting a 3D List to a 3D NumPy array,"A = [[[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0], [0], [0]]]" |
Regular expression in Python sentence extractor,"re.split('\\.\\s', re.sub('\\.\\s*$', '', text))" |
How to plot with x-axis at the top of the figure?,ax.xaxis.set_ticks_position('top') |
Python load json file with UTF-8 BOM header,json.loads(open('sample.json').read().decode('utf-8-sig')) |
How to get multiple parameters with same name from a URL in Pylons?,request.params.getall('c') |
How to sort tire sizes in python,"sorted(nums, key=lambda x: tuple(reversed(list(map(int, x.split('/'))))))" |
python convert list to dictionary,"l = ['a', 'b', 'c', 'd', 'e']" |
Removing key values pairs from a list of dictionaries,"[dict((k, v) for k, v in d.items() if k != 'mykey1') for d in mylist]" |
How do convert a pandas/dataframe to XML?,df.to_xml('foo.xml') |
How to convert a pandas DataFrame into a TimeSeries?,df.unstack() |
Selenium open pop up window [Python],"driver.find_element_by_css_selector(""a[href^='javascript']"").click()" |
How to find the real user home directory using python?,os.path.expanduser('~user') |
How to get a function name as a string in Python?,my_function.__name__ |
how to uniqify a list of dict in python,[dict(y) for y in set(tuple(x.items()) for x in d)] |
How can I get href links from HTML using Python?,"soup.findAll('a', attrs={'href': re.compile('^http://')})" |
Splitting string and removing whitespace Python,"[item.strip() for item in my_string.split(',')]" |
How to split a string into integers in Python?,"map(int, '42 0'.split())" |
Sum of all values in a Python dict,sum(d.values()) |
How to use variables in SQL statement in Python?,"cursor.execute('INSERT INTO table VALUES (%s, %s, %s)', (var1, var2, var3))" |
random Decimal in python,decimal.Decimal(random.randrange(10000)) / 100 |
How do I get rid of Python Tkinter root window?,root.destroy() |
python getting a list of value from list of dict,[d['value'] for d in l if 'value' in d] |
How to find a value in a list of python dictionaries?,any(d['name'] == 'Test' for d in label) |
Convert a Pandas DataFrame to a dictionary,df.set_index('ID').T.to_dict('list') |
python selenium click on button,driver.find_element_by_css_selector('.button .c_button .s_button').click() |
Combine two Pandas dataframes with the same index,"pandas.concat([df1, df2], axis=1)" |
How do I convert user input into a list?,"['p', 'y', 't', 'h', 'o', 'n', ' ', 'r', 'o', 'c', 'k', 's']" |
"In python 2.4, how can I execute external commands with csh instead of bash?","os.system(""zsh -c 'echo $0'"")" |
Convert a string to integer with decimal in Python,int(s.split('.')[0]) |
How to convert numpy.recarray to numpy.array?,"a.astype([('x', '<f8'), ('y', '<f8'), ('z', '<f8')]).view('<f8')" |
Find an element in a list of tuples,"[(x, y) for x, y in a if x == 1]" |
How to replace repeated instances of a character with a single instance of that character in python,"re.sub('\\*+', '*', text)" |
How to erase the file contents of text file in Python?,"open('file.txt', 'w').close()" |
How can I color Python logging output?,logging.info('some info') |
Regex punctuation split [Python],"re.split('\\W+', 'Words, words, words.')" |
Sorting dictionary by values in python,"sorted(iter(dict_.items()), key=lambda x: x[1])" |
Pandas: How can I remove duplicate rows from DataFrame and calculate their frequency?,"df1.groupby(['key', 'year']).size().reset_index()" |
Convert int to ASCII and back in Python,ord('a') |
How can I resize the root window in Tkinter?,root.geometry('500x500') |
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 find the last occurrence of an item in a Python list,len(li) - 1 - li[::-1].index('a') |
Python date string formatting,my_date.strftime('%-m/%-d/%y') |
Removing key values pairs from a list of dictionaries,"[{k: v for k, v in d.items() if k != 'mykey1'} for d in mylist]" |
Custom sorting in pandas dataframe,df.sort('m') |
How to remove whitespace from end of string in Python?,"print('{}, you won!'.format(name))" |
Conditional replacement of row's values in pandas DataFrame,df.groupby('ID').cumcount() + 1 |
How to download a file via FTP with Python ftplib,"ftp.retrbinary('RETR %s' % filename, file.write)" |
Sorting Python list based on the length of the string,xs.sort(key=lambda s: len(s)) |
How do I check if all elements in a list are the same?,len(set(mylist)) == 1 |
I want to plot perpendicular vectors in Python,plt.show() |
convert string to hex in python,hex(ord('a')) |
Changing image hue with Python PIL,new_img.save('tweeter_green.png') |
How to throw an error window in Python in Windows,"ctypes.windll.user32.MessageBoxW(0, 'Error', 'Error', 0)" |
How to add a line parallel to y axis in matplotlib?,plt.show() |
Strip HTML from strings in Python,"re.sub('<[^<]+?>', '', text)" |
Python: import a file from a subdirectory,__init__.py |
How to get the length of words in a sentence?,[len(x) for x in s.split()] |
Create a list of integers with duplicate values in Python,[(i // 2) for i in range(10)] |
Regular expression matching all but a string,"re.findall('-(?!aa|bb)([^-]+)', string)" |
Regular expression matching all but a string,"re.findall('-(?!aa-|bb-)([^-]+)', string)" |
"In Django, how do I select 100 random records from the database?",Content.objects.all().order_by('?')[:100] |
Python ASCII to binary,bin(ord('P')) |
Replace value in any column in pandas dataframe,"df.replace('-', 'NaN')" |
Python: How to sort a dictionary by key,"sorted(iter(result.items()), key=lambda key_value: key_value[0])" |
How can I configure Pyramid's JSON encoding?,"json.dumps(json.dumps({'color': 'color', 'message': 'message'}))" |
Replace a string in list of lists,"[['string 1', 'atest string:'], ['string 1', 'test 2: anothertest string']]" |
How to search a list of tuples in Python,"[i for i, v in enumerate(L) if v[0] == 53]" |
Image transformation in OpenCV,"cv2.imwrite('warped.png', warped)" |
Unescaping Characters in a String with Python,"""""""\\u003Cp\\u003E"""""".decode('unicode-escape')" |
How can I plot hysteresis in matplotlib?,"ax.scartter(XS, YS, ZS)" |
Adding url to mysql row in python,"cursor.execute('INSERT INTO `index`(url) VALUES(%s)', (url,))" |
Symlinks on windows?,"kdll.CreateSymbolicLinkW('D:\\testdirLink', 'D:\\testdir', 1)" |
Fastest way to sort each row in a pandas dataframe,"df.sort(df.columns, axis=1, ascending=False)" |
How to apply linregress in Pandas bygroup,"linregress(df['col_X'], df['col_Y'])" |
How can I convert a Python dictionary to a list of tuples?,"[(k, v) for k, v in a.items()]" |
"Run a python script from another python script, passing in args",os.system('script2.py 1') |
Sort list of date strings,"sorted(d, key=lambda x: datetime.datetime.strptime(x, '%m-%Y'))" |
How can I generate a list of consecutive numbers?,list(range(9)) |
Method to sort a list of lists?,L.sort(key=operator.itemgetter(1)) |
How do I use matplotlib autopct?,plt.show() |
"Pythonic way to fetch all elements in a dictionary, falling between two keys?","dict((k, v) for k, v in parent_dict.items() if 2 < k < 4)" |
Python - Extract folder path from file path,os.path.dirname(os.path.abspath(existGDBPath)) |
how do i return a string from a regex match in python,"imtag = re.match('<img.*?>', line).group(0)" |
How to pass parameters to a build in Sublime Text 3?,"{'cmd': ['python', '$file', 'arg1', 'arg2']}" |
Expat parsing in python 3,"parser.ParseFile(open('sample.xml', 'rb'))" |
Splitting strings in python,"re.findall('\\[[^\\]]*\\]|""[^""]*""|\\S+', s)" |
How to get only the last part of a path in Python?,os.path.basename(os.path.normpath('/folderA/folderB/folderC/folderD/')) |
How to convert this list into a dictionary,"dict([(e[0], int(e[1])) for e in lst])" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.