开满天机
我建议使用str索引器,如果由于值不存在而不匹配,则返回NaN:#if need slect first tupledf['new'] = df['Match'].str[0]#if need select second tuple and first element of tupledf['new'] = df['Match'].str[1].str[0]样品:a = [[('word1','','','')], [('word2','','',''),('word1', )], [('word2','','',''),('word1', ),('word3','','','')]]df = pd.DataFrame({'ID':[1,2,3], 'Match':a})df['new1'] = df['Match'].str[0]df['new2'] = df['Match'].str[1].str[0]print (df) ID Match new1 new20 1 [(word1, , , )] (word1, , , ) NaN1 2 [(word2, , , ), (word1,)] (word2, , , ) word12 3 [(word2, , , ), (word1,), (word3, , , )] (word2, , , ) word1编辑:如果值是字符串,请使用ast.literal_eval:import astdf['Match'] = df['Match'].astype(str)df['Match'] = df['Match'].apply(ast.literal_eval)df['new2'] = df['Match'].str[0]print (df) ID Match new20 1 [(word1, , , )] (word1, , , )1 2 [(word2, , , ), (word1,)] (word2, , , )2 3 [(word2, , , ), (word1,), (word3, , , )] (word2, , , )