定义列表L1、元组T1和字典D1:L1=[1,-2,2.3,'hq'],T1=(2,4,7,'hp'),D1={1:'cat',2:'dog',3:'duck',4:'fish'}。构造序列s1,值为L1,默认索引,并将其输出;构造序列s2,值为T1,索引为a,b,c,d,并将其输出;构造序列s3,值为D1的value,索引为D1的key,并将其输出; ② 定义列表L2=[1,2,3,4,5,6,np.nan,7,8,9,10],把列表L2转化为序列s4,去掉s4中空值后赋值为s5,对s5求和、求平均值、求最大值、求最小值;
时间: 2023-05-31 14:04:53 浏览: 145
①
s1 = pd.Series(L1)
print(s1)
s2 = pd.Series(T1, index=['a', 'b', 'c', 'd'])
print(s2)
s3 = pd.Series(D1.values(), index=D1.keys())
print(s3)
②
L2 = [1,2,3,4,5,6,np.nan,7,8,9,10]
s4 = pd.Series(L2)
s5 = s4.dropna()
print("Sum:", s5.sum())
print("Mean:", s5.mean())
print("Max:", s5.max())
print("Min:", s5.min())
阅读全文