Home Article Practice Python

Python

2021-12-23 09:23  views:1835  source:安洛玛的无知    

import csv
import pandas as pd
from io import stringio
from urllib import request
#读取数字串
data=request.urlopen(url).read().decode(enfing='gb2312')
#3.将字符串转换为 StringIO对象,使其具有文件属性
dfile=StringIO(data)
#4.将流转换为可迭代的reader(csv row)
creader=csv.reader(dfile)
#5.其他转换、操作
dlists = [rw for rw in creader]
#6.取第一行列名数据
columnName=dlists[0]
#7.取其他行数据
KC2020=pd.DataFrame(dlists[1:])
# 8.重新设置列名
KC2020.columns=columnName
print(len(KC2020))
drop_duplicates(keep='first')#去重
sort_values (by='xxx')#排序
to_excel('123.xlsx')
to_csv('123.csv')
ascending=False#倒序
#可视化
#课程折扣的可视化分析
import matplotlib.pyplot as plt
import numpy as np
#为了防止出现中文乱码,在这里设置一下
plt.rcParams['font.sans-serif']=['SimSun']
plt.rcParams['axes.unicode_minus']=False
#画图
x=np.random.rand(zk2020.shape[0])
y=zk2020['课程折扣率']
s=zk2020['课程折扣率']*2
plt.figure(figsize=(10, 7))
plt.scatter(x,y,s=s,color='#8A93F8',marker='o')
plt.title("课程折扣率气泡图",fontsize=18)
plt.ylabel("比率")
plt.savefig('zk2020001.png')



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)