相关文章推荐
追风的大象  ·  ASP.NET ...·  5 月前    · 
任性的风衣  ·  Your file appears not ...·  9 月前    · 
个性的豆浆  ·  Spring Security ...·  1 年前    · 
睿智的椰子  ·  C++ ...·  1 年前    · 
dataFrame如何筛选包含指定字符的列[x for x in df.columns if '指定字符' in x]dataFrame如何筛选包含指定字符的行df[df['列名'].str.contains('指定字符')] resault = df ['某 名'].str.contains('某 字符 串') resault.fillna(value=False,inplace = True) df [resault] 这个是通过str.contains,返回的true或者false,然后为了以防万一有空值,所以用fillna处理,将空值替换成Flase之后用参数i search_cols = [col for col in df .columns if 'keywords' in col] print(search_cols) df 5 = df [search_cols] # 方法2 search_cols= df .filter(like='keywords').columns df 4 = df [search_cols] # 在 标签为code这一 中把 包含 size.002027 字符 串的 全部挑出来 data=data[data['code'].str.contains("szse.002027")] # 存入新文件 data.to_csv('2027.csv',index=False)
您可以使用 pandas 的 str.contains() 方法来 筛选 包含 特定 字符 串的 。例如,假设您的 DataFrame 名称为 df ,您想要 筛选 包含 字符 串 "apple" 的 ,您可以使用以下代码: df [ df .columns[ df .apply(lambda col: col.str.contains('apple')).any()]] 这将返回一个新的 DataFrame,其中 包含 所有 包含 字符 串 "apple" 的