numpy、pandas、matplotlib例题

import numpy as np
a=np.array([1,2,3])
print(a)
[1 2 3]
import numpy as np
a = np.array([1,2,3],dtype=np.complex)
print(a)
[1.+0.j 2.+0.j 3.+0.j]


C:\Users\vers\AppData\Local\Temp\ipykernel_2852\1820813101.py:2: DeprecationWarning: `np.complex` is a deprecated alias for the builtin `complex`. To silence this warning, use `complex` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.complex128` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  a = np.array([1,2,3],dtype=np.complex)
import numpy as np
x=np.float32(5)
print('x为;',x)
print('x为对象的data属性:',x.data)
print('x为对象的size属性:',x.size)
print('x为对象的维数:',x.ndim)
y=np.bool_(x)
print('转换为bool类型的x为:',y)
z=np.float16(y)
print('True值转换为float16类型为:',z)

x为; 5.0
x为对象的data属性: <memory at 0x00000297718EBA40>
x为对象的size属性: 1
x为对象的维数: 0
转换为bool类型的x为: True
True值转换为float16类型为: 1.0
import numpy as np
arr=np.array([[0,1,2],[3,4,5]])
print(arr)
print(arr.sum(axis=0))
print(arr.sum(axis=1))
[[0 1 2]
 [3 4 5]]
[3 5 7]
[ 3 12]
import numpy as np
stus_score = np.array([[45,65],[56,78],[34,67],[35,78],[51,76]])
result=[stus_score>50]
print(result)
[array([[False,  True],
       [ True,  True],
       [False,  True],
       [False,  True],
       [ True,  True]])]
import pandas as pd
s=pd.Series([1,3,5,9,6,8])
print(s)
0    1
1    3
2    5
3    9
4    6
5    8
dtype: int64
import pandas as pd
print('--------列表创建series---------')
s1=pd.Series([1,1,1,1,1])
print(s1)
print('--------字典创建series---------')
s2=pd.Series({'Longitude':39,'Latitude':116,'Temperature':23})
print('First value in s2:',s2['Longitude'])
print('--------用序列作series索引-----')
s3=pd.Series([3.4,0.8,2.1,0.3,1.5],range(5,10))
print('First value in s3:',s3[5])
--------列表创建series---------
0    1
1    1
2    1
3    1
4    1
dtype: int64
--------字典创建series---------
First value in s2: 39
--------用序列作series索引-----
First value in s3: 3.4
s2["city"]="beijing"
s2['Temperature']+=2
s2
Longitude           39
Latitude           116
Temperature         25
city           beijing
dtype: object
s3[s3>2]
5    3.4
7    2.1
dtype: float64
stiny = pd.Series({'humidity':84})
s4=s2.append(stiny)
print('------------原Series:-------------\n',s2)
print('------------新Series:-------------\n',s4)
------------原Series:-------------
 Longitude           39
Latitude           116
Temperature         25
city           beijing
dtype: object
------------新Series:-------------
 Longitude           39
Latitude           116
Temperature         25
city           beijing
humidity            84
dtype: object


C:\Users\vers\AppData\Local\Temp\ipykernel_2852\741578432.py:2: FutureWarning: The series.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
  s4=s2.append(stiny)
import matplotlib.pyplot as plt
fig=plt.figure()
ax1=fig.add_subplot(2,2,1)
ax2=fig.add_subplot(2,2,4)

Alt

fig=plt.figure()
ax1=fig.add_subplot(2,2,1)
ax2=fig.add_subplot(2,2,2)
ax3=fig.add_subplot(2,2,3)

Alt

fig,axes=plt.subplots(2,3)
axes

Alt

import numpy as np
import matplotlib.pyplot as plt
xp=np.linspace(-10,10,100)
yp=np.sin(xp)
plt.plot(xp,yp,marker="o")

Alt

import matplotlib.pyplot as plt
import numpy as np
a=np.arange(10)
plt.xlabel('x')
plt.ylabel('y')
plt.plot(a,a*1.5,a,a*2.5,a,a*3.5,a,a*4.5)
plt.legend(['1.5x','2.5x','3.5x','4.5x'])
plt.title('simple lines')
plt.show()

Alt

import numpy as np
import matplotlib.pyplot as plt
fig,axes=plt.subplots(2,1)
plt.subplot(2,1,1)
x=np.linspace(-10,10,100)
y=np.sin(x)
plt.plot(x,y,marker="o")

Alt

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值