In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you Python how to determine whether the string contains only numbers, I believe most people do not understand, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
When using Python for data processing, it is often encountered that a column in DataFrame should be a numeric type, but the non-numeric type is mixed in the field because of the irregularity of the data. For this type of data, it is generally necessary to determine whether each value in the column contains only numbers. The common judgment methods are as follows:
Str.isdecimal () function
Function: returns True if all characters in the string are decimal characters and the string has at least one character, otherwise returns False. Decimal characters refer to the characters that can be used to make up decimal numbers, such as Ubun0660, the Arabic alphanumeric 0.
Str.isdigit () function
Function: if all characters in the string are numeric and there is at least one character, return True, otherwise return False. Numbers include decimal characters and numbers that require special processing, such as compatibility superscript digits. This includes numbers that cannot be used to make up decimal numbers, such as Kharosthi numbers. Strictly speaking, a number is a character whose attribute value is Numeric_Type=Digit or Numeric_Type=Decimal.
Str.isnumeric () function
Returns True if there is at least one character in the string and all characters are numeric characters, otherwise returns False. Numeric characters include numeric characters, as well as all characters with numeric properties set in Unicode, such as Utility 2155, VULGAR FRACTION ONE FIFTH. Formally defined as: numeric characters are characters with characteristic attribute values of Numeric_Type=Digit, Numeric_Type=Decimal or Numeric_Type=Numeric.
Example:
In addition, these three functions do not recognize the character ".", so none of the three functions can determine the string converted by a floating-point number (this requires the use of regular expressions).
The above is all the contents of the article "how Python determines whether a string contains only numbers". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.