Python之Serise基础篇

一维数组Serise

Serise创建的一维数组与Numpy不同之处在于,索引可以显示,并且还可以自定义索引。获取数组没有不同,都可以通过索引。

创建方式:

1 由字典创建,字典的key就是index,values就是values

import numpy as np
import pandas as pd
dic = {'a':1 ,'b':2 , 'c':3, 'd':4, 'e':5}
s = pd.Series(dic)
print(s)
'''
a    1
b    2
c    3
d    4
e    5
dtype: int64
'''

2 由数组创建(一维数组)

import numpy as np
import pandas as pd
arr = np.random.randn(5)
s = pd.Series(arr)
print('===========================”')
print(s)
# 默认index是从0开始,步长为1的数字
print('===========================”')
s = pd.Series(arr, index = ['a','b','c','d','e'],dtype = np.object)
print(s)
# index参数:设置index,长度保持一致
# dtype参数:设置数值类型
'''
===========================”
0   -0.185145
1   -2.112276
2   -1.502122
3    1.018762
4    0.262129
dtype: float64
===========================”
a   -0.185145
b    -2.11228
c    -1.50212
d     1.01876
e    0.262129
dtype: object
'''

注意:random.sample(range(80,100),4),是一个生成数据很好用的方法

注意:剩下的操作参考列表的切片索引等,操作是相同的

 

An indispensable collection of practical tips and real-world advice for tackling common Python problems and taking your code to the next level. Features interviews with high-profile Python developers who share their tips, tricks, best practices, and real-world advice gleaned from years of experience. Sharpen your Python skills as you dive deep into the Python programming language with Serious Python. You’ll cover a range of advanced topics like multithreading and memorization, get advice from experts on things like designing APIs and dealing with databases, and learn Python internals to help you gain a deeper understanding of the language itself. Written for developers and experienced programmers, Serious Python brings together over 15 years of Python experience to teach you how to avoid common mistakes, write code more efficiently, and build better programs in less time. As you make your way through the book’s extensive tutorials, you’ll learn how to start a project and tackle topics like versioning, layouts, coding style, and automated checks. You’ll learn how to package your software for distribution, optimize performance, use the right data structures, define functions efficiently, pick the right libraries, build future-proof programs, and optimize your programs down to the bytecode. You’ll also learn how to: Make and use effective decorators and methods, including abstract, static, and class methods Employ Python for functional programming using generators, pure functions, and functional functions Extend flake8 to work with the abstract syntax tree (AST) to introduce more sophisticated automatic checks into your programs Apply dynamic performance analysis to identify bottlenecks in your code Work with relational databases and effectively manage and stream data with PostgreSQL If you’ve been looking for a way to take your Python skills from good to great, Serious Python will help you get there. Learn from the experts and get seriously good at Python with Serious Python!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值