我想从熊猫数据框中删除列中的某些关键字或字符串。
数据帧df
如下所示:
YEAR WEEK
2019 WK-01
2019 WK-02
2019 WK-03
2019 WK-14
2019 WK-25
2020 WK-06
2020 WK-07
我想从WK-
列中删除0
和WEEK
,以便我的输出看起来像这样:
YEAR WEEK
2019 1
2019 2
2019 3
2019 14
2019 25
2020 6
2020 7
答案 0 :(得分:3)
您可以尝试:
df['WEEK'] = df['WEEK'].str.extract('(\d*)$').astype(int)
输出:
YEAR WEEK
0 2019 1
1 2019 2
2 2019 3
3 2019 14
4 2019 25
5 2020 6
6 2020 7
答案 1 :(得分:3)
删除前三个字符并转换为int。
const Statistics = ({total, good, neutral, bad}) => {
return (
<div>
<Statistic text = "good" val = {good.toFixed(2)} />
<Statistic text = "neutral" val = {neutral.toFixed(2)} />
<Statistic text = "bad" val = {bad.toFixed(2)} />
<Statistic text = "total" val = {total.toFixed(2)} />
<Statistic text = "average" val = {((good - bad) / total).toFixed(2)} />
<Statistic text = "positive" val = {(good / total).toFixed(2) + "%"} />
</div>
)
}