在大熊猫中,如何在public async Task<T> GetByIdIncludes(Expression<Func<T, bool>> predicate, string includes = "")
{
return await _dbContext.Set<T>().Include(includes).Where(predicate).FirstOrDefaultAsync();
}
可能在字符串中的任何位置的所有列中将&
替换为'&'?
例如,在“标题”列中,如果有一个值“ Good &
bad”,如何将其替换为“ Good&bad”?
答案 0 :(得分:1)
使用replace
和regex=True
替换子字符串:
df = pd.DataFrame({'A': ['Good & bad', 'BB', 'CC', 'DD', 'Good & bad'],
'B': range(5),
'C': ['Good & bad'] * 5})
print (df)
A B C
0 Good & bad 0 Good & bad
1 BB 1 Good & bad
2 CC 2 Good & bad
3 DD 3 Good & bad
4 Good & bad 4 Good & bad
df = df.replace('&','&', regex=True)
print (df)
A B C
0 Good & bad 0 Good & bad
1 BB 1 Good & bad
2 CC 2 Good & bad
3 DD 3 Good & bad
4 Good & bad 4 Good & bad
如果只想替换一列:
df['A'] = df['A'].replace('&','&', regex=True)
print (df)
A B C
0 Good & bad 0 Good & bad
1 BB 1 Good & bad
2 CC 2 Good & bad
3 DD 3 Good & bad
4 Good & bad 4 Good & bad
答案 1 :(得分:0)
尝试一下
df['Title'] = titanic_df['Title'].replace("&", "&")