我有一个数据框,其中包含(((
我想要替换的字符.但这样做后我得到错误:
data = [{'Title': 'set1((("a", "b", "c")))'},
{'Title': 'set2((("d", "e", "f")))'},
{'Title': 'set3((("g", "h", "i")))'},
{'Title': 'set4((("j", "k", "l")))'},
{'Title': 'set5((("m", "n", "o")))'},
{'Title': 'set6((("p", "q", "r")))'}]
df = pd.DataFrame(data)
df
# df['Title'] = df['Title'].str.replace('set', 'M') # Works correctly
df['Title'] = df['Title'].str.replace('(((', '>>') # Not working
Run Code Online (Sandbox Code Playgroud)
如何解决此错误以便替换(((
by >>
和)))
by <<
?
我有这个清单:
mylist = ['*', 'Drama', 'Film Noir', 'Mystery', 'Romance', '*', 'Dance', 'Drama', 'Musical', '*', 'Crime', 'Drama', '*', 'Action', 'Drama', 'Period', 'Western', '*', 'Adaptation', 'Based-on', 'Comedy', 'Romance', '*', 'Mystery', 'Thriller', '*', 'Comedy']
Run Code Online (Sandbox Code Playgroud)
显然,元素'*'是分隔列表中的组.如何在'*'之间对元素的出现进行分组?期望的结果如下所示:
expected_list = [('Drama', 'Film Noir', 'Mystery', 'Romance'), ('Dance', 'Drama', 'Musical'), ('Crime', 'Drama'), ('Action', 'Drama', 'Period', 'Western'), ('Adaptation', 'Based-on', 'Comedy', 'Romance'), ('Mystery', 'Thriller'), ('Comedy')]
Run Code Online (Sandbox Code Playgroud) 我正在使用wxPython中的多个wx.Choice控件,并且我需要使用“重置”按钮来单击时恢复默认选项“-选择-”。无法实现这一点,我最近来的就是将其重置为空选项,这不是我们想要的。我希望按下重置按钮时出现默认选项“-选择-”。请参阅下面的代码。
data.py
import wx
class MyFrame1 ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 250,300 ), style = wx.CAPTION|wx.CLOSE_BOX|wx.MINIMIZE_BOX|wx.SYSTEM_MENU|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
DataBox = wx.BoxSizer( wx.HORIZONTAL )
gSizer2 = wx.GridSizer( 0, 2, 0, 0 )
self.Color_Label = wx.StaticText( self, wx.ID_ANY, u"Color:", wx.DefaultPosition, wx.DefaultSize, 0 )
self.Color_Label.Wrap( -1 )
self.Color_Label.SetFont( wx.Font( 13, 70, 90, 90, False, wx.EmptyString ) )
gSizer2.Add( self.Color_Label, 0, wx.ALL, …
Run Code Online (Sandbox Code Playgroud) python ×3
grouping ×1
list ×1
pandas ×1
python-2.7 ×1
tuples ×1
wxpython ×1
wxtextctrl ×1
wxwidgets ×1