pytho入门教程

作者 : admin 本文共1444个字,预计阅读时间需要4分钟 发布时间: 2024-06-9 共2人阅读

文章目录

  • 随机数据生成的方式
  • list操作方式
  • 数据操作方式
  • 处理缺失数据
  • 数据框操作方式
  • 画图的方式

随机数据生成的方式

# 随机生成数据的方式
# 1. 随机生成10-20之间的浮点数
holdForce = random.uniform(10,20)
# print(holdForce)

# 2.for循环输出50个数据的方式
# for i in range(50):
#     print(random.uniform(10,20))

# 3.其他的写法方式
feelForce=[random.uniform(10,20) for i in range(50)]
parent=np.array(feelForce)
# print(parent)

list操作方式

# 4.list方式
storeForce=list(range(20))
# print(storeForce)

# 5.list数据过滤
filterForce=list(filter(lambda x:x>15,storeForce))
print(filterForce)

数据操作方式

# 1.数据的方式
lickForce=pd.Series([1,2,3],index=['a','b','c'])
# print(lickForce)
# print(lickForce['a'])
# print(lickForce[1:3])


# 2. json 数据格式
holdFroce=pd.Series({'a':1,'b':2},)
# print(holdFroce)

# 3. 判断a是否在里面
stringFroce="cqqq"
stockFroce='c' in stringFroce
print(stockFroce)

处理缺失数据


#1.数据处理的方式
pigForce=pd.Series(random.uniform(10,20) for i in range(9))
cowForce=pd.Series(random.uniform(10,21) for i in range(10))
# pigCowAdd=pigForce+cowForce;
# print(pigCowAdd)
# 想加存在俩个数据存在缺失数据的方式
# pigCowAdd= pigForce.add(cowForce)
# print(pigCowAdd)
# 缺失数据没有了
pigCowAdd= pigForce.add(cowForce,fill_value=0)
print(pigCowAdd)

数据框操作方式


# 1.数据框的方式
cowForce=pd.DataFrame({'belle':["高级","中级","低级"],'magicain':[1,2,3],"land":[1,2,3]})
# print(cowForce)
# 2.数据操作的方式
# 行和列的方式
# print(cowForce['belle'][0])
# 行和列的操作方式
# print(cowForce.loc[1]["belle"])

画图的方式

# 画图的方式
import matplotlib.pyplot as plt
x = np.linspace(-100, 100, 100)
y = np.linspace(-100, 100, 100)
plt.plot(x,y,color='blue',label='y=x')
plt.show()


x = [random.uniform(10,20) for i in range(9)]
plt.bar(np.arange(len(x)),x,align='edge',color="red")
plt.show()
本站无任何商业行为
个人在线分享-虚灵IT资料分享 » pytho入门教程
E-->