我想从同一df的另一列中提取具有条件的数据帧的值。
A B
0 2 10
1 3 60
2 7 50
3 1 100
我只想从A
中获取B
值大于2的值,并用固定值= 5填充从B
中获取的值
赞:
A B
0 2 5
1 3 60
2 7 50
3 1 5
答案 0 :(得分:1)
使用:
import numpy as np
df['B'] = np.where(df['A']>2,df['B'],5)
df
A B
0 2 5
1 3 60
2 7 50
3 1 5
答案 1 :(得分:1)
使用class AceEditor extends React.Component {
constructor(props, context) {
super(props, context);
this.editor = React.createRef();
}
componentDidMount() {
this.setState({
code: "Test text"
})
}
render() {
const {code} = this.state;
return (
<div>
<Button onClick={() => {
this.editor.current.editor.undo()
}}/>
<AceEditor
ref={this.editor}
value={code}
// more props
onLoad={editor => {
const session = editor.getSession();
const undoManager = session.getUndoManager();
undoManager.reset();
session.setUndoManager(undoManager);
}}
/>
</div>
);
}
}
:
pandas.Series.where
输出:
df["B"] = df["B"].where(df["A"].gt(2), 5)
print(df)