简体   繁体   English

熊猫如何顺序检查列中的值

[英]pandas how to check the values in a column is sequential

I like to know how to check the int/float values in a column is sequential, eg in the following df , 2 of 3 columns are considered to have sequential values since their differences are 1; 我想知道如何检查一列中的int/float值是顺序的,例如在以下df ,由于3列中的2列之差为1,因此认为它们具有顺序值;

inv_id   ven_id    pay_id
123      1.22      1230
124      2.22      1234
125      3.22      1235
126      4.22      1240
127      5.22      1241

inv_id and ven_id are sequential since the differences between values are all equal 1; inv_idven_id是顺序的,因为值之间的差都等于1; pay_id is not sequential, since the differences between some of the values are 1. pay_id不是顺序的,因为某些值之间的差异为1。

Based on piRSquared's comment. 基于piRSquared的评论。 You should first select only the numeric columns on your df: 您应该首先只选择df上的数字列:

numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64'] numeric_df = df.select_dtypes(include=numerics)

Then you should run: 然后,您应该运行:

numeric_df.diff().dropna().eq(1).all()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM