国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

利用python實(shí)現(xiàn)數(shù)據(jù)分析

2020-02-23 04:13:51
字體:
供稿:網(wǎng)友

1:文件內(nèi)容格式為json的數(shù)據(jù)如何解析

import json,os,syscurrent_dir=os.path.abspath(".")filename=[file for file in os.listdir(current_dir) if ".txt" in file]#得到當(dāng)前目錄中,后綴為.txt的數(shù)據(jù)文件fn=filename[0] if len(filename)==1 else "" #從list中取出第一個(gè)文件名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:出現(xiàn)頻率統(tǒng)計(jì)

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

3:重新加載module的方法py3

import importlibimport.reload(modulename)

4:pylab中包含了哪些module

   from pylab import *

等效于下面的導(dǎo)入語句:

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 洛阳市| 成武县| 区。| 法库县| 礼泉县| 蓬莱市| 三原县| 临江市| 威海市| 沈阳市| 施甸县| 富源县| 阿拉善左旗| 六安市| 德安县| 黎城县| 大厂| 周宁县| 腾冲县| 北川| 兖州市| 德安县| 宁化县| 延长县| 毕节市| 清丰县| 惠水县| 集贤县| 青铜峡市| 三原县| 赤峰市| 胶州市| 永仁县| 靖远县| 大兴区| 永兴县| 盖州市| 浪卡子县| 翼城县| 东源县| 墨脱县|