Coding Up — Python Data-Parse Teaching
Yo is here to share with you today that I use a Python suite Parse in my work. I almost didn't see his introductory text on the Internet. I think it's very useful and intuitive, so I want to write a record. Like re (regular expression), it is used to capture the data we want
1. Of course, you must first download this package, I use anaconda to download (open your Anaconda prompt and type the following string)
pip install parse
2. parse()
As long as you type a {}, it will grab the data you want according to the position of {}, enter the name you want in {}, like {name}, it will help you parse it into a dictionary form ,perfectly worked
a. Warning: parse(a,b) the length of a and b must be the same, otherwise it will not catch
b. Chinese can also play
3. search()
I personally like this function very much, because it is super intuitive, and it does not have the problems that parse() will encounter. You can easily find the corresponding data according to the pattern before and after the data you want, but if you do not add the following pattern, It will only catch one word, such as Age:26, if you type Age:{} it will only catch 2, then there are two ways to solve it, one is to change it to {:d} or add the following pattern , Age:{}, (one more comma), it catches
4. findall()
1. In this way, we can quickly put the data we want into a list, so that we can make a dataframe later
, csv, very easy to use
2. It is very suitable for grabbing html files
5. compile()
If you feel that it is very troublesome to type the data we are looking for every time, as long as you use it, you only need to enter it once and you can always use it on different text(type(str))
Hope it helps you~~
If you have any questions, you can also ask me directly, I'm afraid I can't help you, because I may not, but we can study together, haha
Reference source:
Like my work? Don't forget to support and clap, let me know that you are with me on the road of creation. Keep this enthusiasm together!
- Author
- More