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