I'm having a pandas DataFrame df. I want to replace ↑(a space after ↑) with +, and ↓(a space after ↓) with -. For example, df.a[0](values ↑ 0.69%) replace with +0.69%.
df['last_month'] = df['last_month'].replace(r"↑ ","")is not right. Why?
data = [{"a":"↑ 0.69%","b":"↓ 9.93%"},{"a":"↓ 0.46%","b":"↑ 3.3%"},{"a":"↓ 0.78%","b":"↓ 3.43%"}]
df = pd.DataFrame(data)
df
a b
0 ↑ 0.69% ↓ 9.93%
1 ↓ 0.46% ↑ 3.3%
2 ↓ 0.78% ↓ 3.43%
In my raw data, ↑ is an unicode, so it didn't work. In the demo data, ↑ is a str(bytes), so df['last_month'] = df['last_month'].replace(r"↑ ","") works actually like MaxU's. But how to replace when DataFrame values are unicode?
