尝试通过选择 column 的特定值来切片数据帧:
import pandas as pd
import numpy as np
df = pd.DataFrame({'A': 'foo bar foo bar foo bar foo foo'.split(),
'B': 'one one two three two two one three'.split(),
'C': np.arange(8), 'D': np.arange(8) * 2})
mask = df['A'] == 'foo'
df[mask]
这将检索完美的解决方案
A B C D
foo one 0 0
foo two 2 4
foo two 4 8
foo one 6 12
foo three 7 14
但是当试图用标准输入函数赋予价值时……我得到了一个空的数据框。
import pandas as pd
import numpy as np
df = pd.DataFrame({'A': 'foo bar foo bar foo bar foo foo'.split(),
'B': 'one one two three two two one three'.split(),
'C': np.arange(8), 'D': np.arange(8) * 2})
mask = df['A'] == input("enter: ")
输入:'富'
df[mask]
输出:
Empty DataFrame
Columns: [A, B, C, D]
Index: []
缥缈止盈
相关分类