显示值以特定数字熊猫结尾



我有一个数据帧:

index  assets
1     12345
2     54343
3     39483000
4     2543553
5     22425000
6     5342334345
7     244224000

我想显示以"000"结尾的值。

Df

index  assets
3      39483000
5      22425000
7     244224000

您可以使用pd.Series.astype(str)assets转换为str后使用pd.Series.str.endswith并使用boolean indexing

df[df.assets.astype(str).str.endswith('000')]
index     assets
2      3   39483000
4      5   22425000
6      7  244224000

pd.Series.modpd.Series.eq和使用boolean indexing

df[df.assets.mod(1000).eq(0)]
index     assets
2      3   39483000
4      5   22425000
6      7  244224000

最新更新