国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 丹江口市| 高唐县| 太康县| 伊通| 叙永县| 收藏| 阿城市| 三门峡市| 天门市| 广州市| 潮州市| 普宁市| 铜鼓县| 碌曲县| 屯留县| 辽阳县| 晋州市| 菏泽市| 澜沧| 南陵县| 辽阳县| 叙永县| 吉安市| 原阳县| 营山县| 威海市| 大名县| 博白县| 安康市| 阜康市| 梁河县| 阳新县| 铜鼓县| 兴文县| 祁门县| 康乐县| 大悟县| 中江县| 陵川县| 容城县| 马山县|