没有合适的资源?快使用搜索试试~ 我知道了~
Pandas Cheat Sheet
需积分: 13 15 下载量 76 浏览量
2018-01-25
10:54:06
上传
评论
收藏 539KB PDF 举报
温馨提示
# All categories (/pandas) | # Import, version (/pandas/import-version) | # Create data objects (/pandas/create-data-objects) | # View data info (/pandas/view-data-info) | # Visualize data (/pandas/visualize-data) | # Select data (/pandas/select-data) | # Manage unique & empty data (/pandas/manage-unique- empty-data) | # Modify & transform data (/pandas/modify-transform-data) | # Iterate over data (/pandas/iterate-over-data) | # Aggregate data (/pandas/aggregate-data) | # Save & Load (/pandas/save-load) |
资源推荐
资源详情
资源评论
2018/1/16 Pandas Cheat Sheet
https://mycheatsheets.com/pandas 1/42
(mailto:?subject=Pandas%20Cheat%20Sheet&body=https%3A%2F%2Fmycheatsheets.com%2Fpandas)
(https://twitter.com/share?url=https%3A%2F%2Fmycheatsheets.com%2Fpandas&text=Pandas%20Cheat%20Sheet)
(https://facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmycheatsheets.com%2Fpandas)
(https://plus.google.com/share?url=https%3A%2F%2Fmycheatsheets.com%2Fpandas)
(https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmycheatsheets.com%2Fpandas)
11
38
See also: NumPy Cheat Sheet (/numpy) | Matplotlib Cheat Sheet (/matplotlib) | All Cheat Sheets (/)
Pandas | MyCheatSheets.com (/pandas)
| # All categories (/pandas) | # Import, version (/pandas/import-version) |
# Create data objects (/pandas/create-data-objects) | # View data info
(/pandas/view-data-info) | # Visualize data (/pandas/visualize-data) | # Select data
(/pandas/select-data) | # Manage unique & empty data (/pandas/manage-unique-
empty-data) | # Modify & transform data (/pandas/modify-transform-data) |
# Iterate over data (/pandas/iterate-over-data) | # Aggregate data
(/pandas/aggregate-data) | # Save & Load (/pandas/save-load) |
Pandas > All categories
Name
Code
⇨
Output
Add new columns (/pandas/dataframe-add-new-columns)
dataframe = pandas.DataFrame(numpy.random.randint(0,100,size=(5, 3)),
columns=['C1','C2','C3'])
print ("dataframe")
print (dataframe)
print ("dataframe added new columns")
dataframe['C1p10']=dataframe['C1'] + 10
dataframe['C101']=101
print (dataframe)
⇨
SEARCH
2018/1/16 Pandas Cheat Sheet
https://mycheatsheets.com/pandas 2/42
dataframe
C1 C2 C3
0 14 81 99
1 33 89 95
2 60 27 21
3 19 85 44
4 20 62 57
dataframe added new columns
C1 C2 C3 C1p10 C101
0 14 81 99 24 101
1 33 89 95 43 101
2 60 27 21 70 101
3 19 85 44 29 101
4 20 62 57 30 101
Append dataframes (/pandas/append-dataframes)
dataframe1 = pandas.DataFrame(numpy.random.randint(0,10,size=(3, 2)),
columns=['C1','C2'])
dataframe2 = pandas.DataFrame(numpy.random.randint(0,10,size=(3, 2)),
columns=['C1','C2'])
print ("dataframe1")
print (dataframe1)
print ("dataframe2")
print (dataframe2)
dataframe3 = dataframe1.append(dataframe2,ignore_index = True)
print ("appended dataframes")
print (dataframe3)
⇨
dataframe1
C1 C2
0 4 5
1 9 1
2 3 6
dataframe2
C1 C2
0 3 8
1 8 8
2 5 6
appended dataframes
C1 C2
0 4 5
1 9 1
2 3 6
3 3 8
4 8 8
5 5 6
Apply aggregate functions (/pandas/apply-aggregate-functions)
This website is using cookies.
We use them to give you the best experience. If
you continue using our website, we'll assume
that you are happy to receive all cookies on this
website.
x
2018/1/16 Pandas Cheat Sheet
https://mycheatsheets.com/pandas 3/42
dataframe = pandas.DataFrame(numpy.random.randint(0,10,size=(5, 3)),
columns=['C1','C2','C3'])
print ("dataframe")
print (dataframe)
print ("aggregates")
aggregates = dataframe.agg(['sum', 'max','mean'])
print (aggregates)
⇨
dataframe
C1 C2 C3
0 4 3 0
1 5 0 9
2 8 9 2
3 6 7 5
4 5 9 2
aggregates
C1 C2 C3
sum 28.0 28.0 18.0
max 8.0 9.0 9.0
mean 5.6 5.6 3.6
Apply function along axis (/pandas/apply-function-along-axis)
dataframe = pandas.DataFrame(numpy.random.randint(0,100,size=(5, 2)),
columns=['C1','C2'])
print ("dataframe")
print (dataframe)
# sum for columns
sum_columns = dataframe[['C1','C2']].apply(sum,axis=0)
print ("sum for columns")
print (sum_columns)
# sum for rows
sum_rows = dataframe[['C1','C2']].apply(sum,axis=1)
print ("sum for rows")
print (sum_rows)
⇨
Continue Learn more
(/init/default/terms)
This website is using cookies.
We use them to give you the best experience. If
you continue using our website, we'll assume
that you are happy to receive all cookies on this
website.
x
2018/1/16 Pandas Cheat Sheet
https://mycheatsheets.com/pandas 4/42
dataframe
C1 C2
0 56 2
1 94 89
2 0 56
3 62 80
4 80 98
sum for columns
C1 292
C2 325
dtype: int64
sum for rows
0 58
1 183
2 56
3 142
4 178
dtype: int64
Apply function to dataframe (map/lambda) (/pandas/dataframe-apply-function-
maplambda)
dataframe = pandas.DataFrame(numpy.random.randint(0,100,size=(5, 2)),
columns=['C1','C2'])
print ("dataframe")
print (dataframe)
# cross-tabulation of two factors (default is a frequency table)
dataframe['C1'] = dataframe['C1'].map(lambda x: x-100)
print ("modified dataframe")
print (dataframe)
⇨
dataframe
C1 C2
0 27 35
1 46 38
2 21 98
3 34 30
4 76 8
modified dataframe
C1 C2
0 -73 35
1 -54 38
2 -79 98
3 -66 30
4 -24 8
Apply function to each element (/pandas/dataframe-apply-function-to-each-
element)
Continue Learn more
(/init/default/terms)
This website is using cookies.
We use them to give you the best experience. If
you continue using our website, we'll assume
that you are happy to receive all cookies on this
website.
x
2018/1/16 Pandas Cheat Sheet
https://mycheatsheets.com/pandas 5/42
dataframe = pandas.DataFrame(numpy.random.randint(0,100,size=(5, 2)),
columns=['C1','C2'])
print ("dataframe")
print (dataframe)
function_result = dataframe.applymap(lambda x: x*10)
print ("apply result")
print (function_result)
⇨
dataframe
C1 C2
0 54 11
1 31 59
2 81 76
3 42 46
4 8 24
apply result
C1 C2
0 540 110
1 310 590
2 810 760
3 420 460
4 80 240
Calculate correlation (/pandas/calculate-dataframe-correlation)
dataframe = pandas.DataFrame(numpy.random.randint(0,100,size=(5, 3)),
columns=['C1','C2','C3'])
print ("dataframe")
print (dataframe)
print ("dataframe correlation")
print (dataframe.corr())
⇨
dataframe
C1 C2 C3
0 82 71 74
1 62 12 8
2 97 86 26
3 26 98 48
4 5 97 29
dataframe correlation
C1 C2 C3
C1 1.000000 -0.339904 0.107885
C2 -0.339904 1.000000 0.456666
C3 0.107885 0.456666 1.000000
Calculate covariance (/pandas/calculate-dataframe-covariance)
Continue Learn more
(/init/default/terms)
This website is using cookies.
We use them to give you the best experience. If
you continue using our website, we'll assume
that you are happy to receive all cookies on this
website.
x
剩余41页未读,继续阅读
资源评论
tjybrentao
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功