利用python實現資料分析

來源:互聯網
上載者:User
1:檔案內容格式為json的資料如何解析

import json,os,syscurrent_dir=os.path.abspath(".") filename=[file for file in os.listdir(current_dir) if ".txt" in file]#得到目前的目錄中,尾碼為.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:出現頻率統計

import randomfrom collections import Counterfruits=[random.choice(["apple","cherry","orange","pear","watermelon","banana"]) for i in range(20)]print(fruits) #查看所有水果出現的次數 cover_fruits=Counter(fruits)for fruit,times in cover_fruits.most_common(3):  print(fruit,times) ########運行結果如下:apple在fruits裡出了5次apple 5 banana 4pear 4

3:重新載入module的方法py3

import importlibimport.reload(modulename)

4:pylab中包含了哪些module

from pylab import *

等效於下面的匯入語句:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.