Using Python for data analysis

Source: Internet
Author: User
1: How the file content format is JSON data parsing

Import Json,os,syscurrent_dir=os.path.abspath (".") filename=[file for file in Os.listdir (Current_dir) if ". txt" in file] #得到当前目录中, data file suffix. txt fn=filename[0] If len (filename) ==1 Else "" #从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: Occurrence Frequency statistics

Import Randomfrom Collections Import Counterfruits=[random.choice (["Apple", "Cherry", "orange", "pear", "watermelon", " Banana "]) for I in range]print (fruits) #查看所有水果出现的次数 cover_fruits=counter (fruits) for fruit,times in Cover_ Fruits.most_common (3):  print (fruit,times) ####### #运行结果如下: Apple 5 times in Fruits Apple 5 Banana 4pear 4

3: Method of Reloading Module Py3

Import Importlibimport.reload (ModuleName)

Which module is included in the 4:pylab

From Pylab Import *

Equivalent to the following import statement:

From Pylab import *from numpy import *from scipy import *import matplotlib

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.