Use python for data analysis and python for data analysis

Source: Internet
Author: User

Use python for data analysis and python for data analysis

1: How to parse json data

Import json, OS, syscurrent_dir = OS. path. abspath (". ") filename = [file for file in OS. listdir (current_dir) if ". txt "in filepath must be included in the current directory. The data file fn = filename [0] if len (filename) = 1 else" "# retrieve the first file name from the list if fn: # means we got a valid filename fd = open (fn) content = [json. loads (line) for line in fd] else: print ("no txt file in current directory") sys. exit (1) for linedict in content: for key, value in linedict. items (): print (key, value) print ("\ n ")

2: Frequency Statistics

Import randomfrom collections import Counterfruits = [random. choice (["apple", "cherry", "orange", "pear", "watermelon", "banana"]) for I in range (20)] print (fruits) # view the number of times that all fruits appear cover_fruits = Counter (fruits) for fruit, times in cover_fruits.most_common (3): print (fruit, times) ######## running result: apple posted 5 times in fruits, apple 5 banana 4 pear 4

3: Reload module method py3

import importlibimport.reload(modulename)

4: modules included in pylab

   from pylab import *

It is equivalent to the following import statement:

  from pylab import *  from numpy import *  from scipy import *  import matplotlib

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.