楼主: casey_c
1446 4

[程序分享] Python 基础 [推广有奖]

  • 0关注
  • 10粉丝

博士生

92%

还不是VIP/贵宾

-

威望
0
论坛币
96 个
通用积分
2.1003
学术水平
2 点
热心指数
15 点
信用等级
2 点
经验
11502 点
帖子
278
精华
0
在线时间
94 小时
注册时间
2016-11-22
最后登录
2022-5-2

楼主
casey_c 发表于 2017-9-19 10:35:46 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币


以下内容转自 数析学院,只节选了部分,有需要的同学可以直接查看原文

导入 Packages

  1. from numpy import *
  2. from pandas import *

  3. #使用 import * 将 所有的包和类导入命名空间
  4. #对于巨大的包你可以通过 from [name] import [class/object]导入一部分
  5. #为了避免命名空间冲突,你也可以重命名你导入的部分

  6. #导入 pandas 并且重命名
  7. import pandas as pd
  8. #导入  Series 和 dataframe 类
  9. from pandas import Series, DataFrame

  10. #常见命名规则:numpy 是 np, pandas 是 pd ,matplotlib 是 plt
  11. import numpy as np
  12. import pandas as pd
  13. import matplotlib.pyplot as plt
复制代码


一、列表

1、生成列表

  1. # 列表 a
  2. a=[0,1,2,3,4,5,6,7,8,9]
  3. a
复制代码
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
2、列表切片
  1. #使用 [x] to 访问在 list 的 x 的元素
  2. #所有 list 都从 0 开始索引
  3. print 'first item', a[0]

  4. #也可以通过使用 -1,-2 等等来索引最后一个、倒数第二个
  5. print 'last item', a[-1]

  6. #也可以使用 : 或 :: 进行切片处理
  7. print 'first three items', a[:3]
  8. print 'last three items', a[-3:]
  9. print 'start at the 4th item', a[3:]
  10. print 'the odd items', a[::2]
复制代码
first item 0last item 9first three items [0, 1, 2]last three items [7, 8, 9]start at the 4th item [3, 4, 5, 6, 7, 8, 9]the odd items [0, 2, 4, 6, 8]
  1. #所有的 list 都有长度, 使用 len(list_name) 来获得list 中元素的数量
  2. #通常,如果 list 中包含数字,那么数学函数可以在 list 上应用
  3. print 'length of list', len(a)
  4. print 'largets number in list', max(a)
  5. print 'smallest number', min(a)
  6. print 'average', mean(a)

  7. #找到 max 和 min 的索引使用 argmax() 和 argmin()
  8. print 'the largest number in the list is', max(a),
  9. 'and is found at index:', argmax(a)
复制代码
length of list 10largets number in list 9smallest number 0average 4.5the largest number in the list is 9 and is found at index: 9
3、添加元素
  1. #通过使用 list_name.append(item),元素可以添加到 list 中

  2. #在列表 a 中添加元素 3
  3. a.append(3)
  4. #添加元素 4
  5. a.append(4)
  6. a
复制代码
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 3, 4]
  1. #最后,通过使用 unique 方法,过滤 list 的重复数据
  2. #使用 sort(list_name)排序 list

  3. print 'sorted list', sort(a)
  4. print 'select distinct values', unique(a)
复制代码
sorted list [0 1 2 3 3 4 4 5 6 7 8 9]select distinct values [0 1 2 3 4 5 6 7 8 9]
以上内容转自 数析学院,其他一些基础内容有时间再补齐,有需要的同学可以直接查看原文
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:python Matplotlib Dataframe Distinct Packages

沙发
西门高 发表于 2017-9-19 10:41:15 来自手机
casey_c 发表于 2017-9-19 10:35
以下内容转自 数析学院,只节选了部分,有需要的同学可以直接查看原文

导入 Packages
谢谢分享

藤椅
casey_c 发表于 2017-9-25 10:47:29

板凳
xiang8482890 在职认证  发表于 2018-2-24 07:56:53
请问原文在哪里?

报纸
casey_c 发表于 2018-3-5 16:16:01
xiang8482890 发表于 2018-2-24 07:56
请问原文在哪里?
百度数析学院

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 01:27