Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_python
提交
002675a9
S
skill_tree_python
项目概览
CSDN 技术社区
/
skill_tree_python
通知
66
Star
14
Fork
6
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_python
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
002675a9
编写于
2月 16, 2022
作者:
F
feilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug
上级
3b8bb843
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
225 addition
and
48 deletion
+225
-48
data/1.python初阶/3.进阶语法/10.字符编码与解码/encode.md
data/1.python初阶/3.进阶语法/10.字符编码与解码/encode.md
+9
-6
data/3.python高阶/2.结构化数据分析工具Pandas/2.数据结构/dataframe.json
data/3.python高阶/2.结构化数据分析工具Pandas/2.数据结构/dataframe.json
+6
-3
data/3.python高阶/2.结构化数据分析工具Pandas/2.数据结构/dataframe.md
data/3.python高阶/2.结构化数据分析工具Pandas/2.数据结构/dataframe.md
+163
-0
data/3.python高阶/2.结构化数据分析工具Pandas/2.数据结构/dataframe.py
data/3.python高阶/2.结构化数据分析工具Pandas/2.数据结构/dataframe.py
+47
-39
未找到文件。
data/1.python初阶/3.进阶语法/10.字符编码与解码/encode.md
浏览文件 @
002675a9
...
@@ -11,8 +11,8 @@ if __name__ == '__main__':
...
@@ -11,8 +11,8 @@ if __name__ == '__main__':
utf8_str
=
unicode_str
.
encode
(
'utf-8'
)
utf8_str
=
unicode_str
.
encode
(
'utf-8'
)
print
(
utf8_str
)
print
(
utf8_str
)
unicode_str_again
=
utf8_str
.
decode
(
'utf-8'
)
# TODO(You):请在此实现代码
print
(
unicode_str_again
)
unicode_str_again
=
...
assert
unicode_str_again
==
unicode_str
assert
unicode_str_again
==
unicode_str
```
```
...
@@ -36,22 +36,25 @@ if __name__ == '__main__':
...
@@ -36,22 +36,25 @@ if __name__ == '__main__':
## 答案
## 答案
```
python
```
python
unicode_str_again
=
utf8_str
.
decode
(
'utf-8'
)
```
```
## 选项
## 选项
### A
### A
```
python
```
python
unicode_str_again
=
utf8_str
.
decode
()
```
```
### B
### B
```
python
```
python
unicode_str_again
=
utf8_str
.
decode
(
'unicode'
)
```
```
### C
### C
```
python
```
python
unicode_str_again
=
utf8_str
.
encode
(
'unicode'
)
```
```
data/3.python高阶/2.结构化数据分析工具Pandas/2.数据结构/dataframe.json
浏览文件 @
002675a9
{
{
"source"
:
"dataframe.py"
,
"source"
:
"dataframe.md"
,
"depends"
:
[],
"exercise_id"
:
119
,
"exercise_id"
:
119
,
"type"
:
"code_options"
"depends"
:
[],
"type"
:
"code_options"
,
"author"
:
"huanhuilong"
,
"notebook_enable"
:
true
}
}
\ No newline at end of file
data/3.python高阶/2.结构化数据分析工具Pandas/2.数据结构/dataframe.md
0 → 100644
浏览文件 @
002675a9
# pandas 创建dataframe
创建dataframe的几种方式
```
python
import
pandas
as
pd
import
numpy
as
np
def
create_dataframe_from_list
():
# TODO(You):请在此编写代码
return
data_df
def
create_dataframe_from_series
():
# TODO(You):请在此编写代码
return
data_df
def
create_dataframe_from_2darray
():
# TODO(You):请在此编写代码
return
data_df
def
create_dataframe_from_dict
():
# TODO(You):请在此编写代码
return
data_df
if
__name__
==
'__main__'
:
print
(
'由数组list组成的字典创建dataframe:'
)
data_df
=
create_dataframe_from_list
()
print
(
data_df
)
print
(
'由Series组成的字典创建dataframe:'
)
data_df
=
create_dataframe_from_series
()
print
(
data_df
)
print
(
'通过二维数组直接创建dataframe:'
)
data_df
=
create_dataframe_from_2darray
()
print
(
data_df
)
print
(
'由字典组成的列表创建dataframe:'
)
data_df
=
create_dataframe_from_dict
()
print
(
data_df
)
```
请选出下列对
**TODO**
部分实现,
**描述错误**
的选项。
## template
```
python
import
pandas
as
pd
import
numpy
as
np
def
create_dataframe_from_list
():
data
=
{
'cloumn_one'
:
np
.
random
.
randint
(
0
,
10
,
size
=
5
),
'cloumn_two'
:
np
.
random
.
randint
(
0
,
10
,
size
=
5
),
'cloumn_three'
:
np
.
random
.
randint
(
0
,
10
,
size
=
5
)
}
data_df
=
pd
.
DataFrame
(
data
)
return
data_df
def
create_dataframe_from_series
():
data
=
{
'cloumn_one'
:
pd
.
Series
(
np
.
random
.
randint
(
0
,
10
,
size
=
5
)),
'cloumn_two'
:
pd
.
Series
(
np
.
random
.
randint
(
0
,
10
,
size
=
5
)),
'cloumn_three'
:
pd
.
Series
(
np
.
random
.
randint
(
0
,
10
,
size
=
5
))
}
data_df
=
pd
.
DataFrame
(
data
)
return
data_df
def
create_dataframe_from_2darray
():
data
=
np
.
random
.
randint
(
0
,
10
,
size
=
9
).
reshape
(
3
,
3
)
data_df
=
pd
.
DataFrame
(
data
,
columns
=
[
'cloumn_one'
,
'cloumn_two'
,
'cloumn_three'
])
return
data_df
def
create_dataframe_from_dict
():
data
=
[{
'cloumn_one'
:
1
,
'cloumn_two'
:
2
,
'cloumn_three'
:
3
},
{
'cloumn_one'
:
5
,
'cloumn_two'
:
6
,
'cloumn_three'
:
7
}]
data_df
=
pd
.
DataFrame
(
data
)
return
data_df
if
__name__
==
'__main__'
:
print
(
'由数组list组成的字典创建dataframe:'
)
data_df
=
create_dataframe_from_list
()
print
(
data_df
)
print
(
'由Series组成的字典创建dataframe:'
)
data_df
=
create_dataframe_from_series
()
print
(
data_df
)
print
(
'通过二维数组直接创建dataframe:'
)
data_df
=
create_dataframe_from_2darray
()
print
(
data_df
)
print
(
'由字典组成的列表创建dataframe:'
)
data_df
=
create_dataframe_from_dict
()
print
(
data_df
)
```
## 答案
```
python
# 该函数的输出数据只含有 cloumn_one cloumn_two cloumn_three 三个列
def
create_dataframe_from_dict
():
data
=
[{
'cloumn_one'
:
1
,
'cloumn_two'
:
2
,
'cloumn_three'
:
3
},
{
'cloumn_one'
:
5
,
'cloumn_two'
:
6
,
'cloumn_xxx'
:
7
}]
data_df
=
pd
.
DataFrame
(
data
)
return
data_df
```
## 选项
### A
```
python
# 该函数的输出数据只含有 cloumn_one cloumn_two cloumn_three 三个列
def
create_dataframe_from_list
():
data
=
{
'cloumn_one'
:
np
.
random
.
randint
(
0
,
10
,
size
=
5
),
'cloumn_two'
:
np
.
random
.
randint
(
0
,
10
,
size
=
5
),
'cloumn_three'
:
np
.
random
.
randint
(
0
,
10
,
size
=
5
)
}
data_df
=
pd
.
DataFrame
(
data
)
return
data_df
```
### B
```
python
# 该函数的输出数据只含有 cloumn_one cloumn_two cloumn_three 三个列
def
create_dataframe_from_series
():
data
=
{
'cloumn_one'
:
pd
.
Series
(
np
.
random
.
randint
(
0
,
10
,
size
=
5
)),
'cloumn_two'
:
pd
.
Series
(
np
.
random
.
randint
(
0
,
10
,
size
=
5
)),
'cloumn_three'
:
pd
.
Series
(
np
.
random
.
randint
(
0
,
10
,
size
=
5
))
}
data_df
=
pd
.
DataFrame
(
data
)
return
data_df
```
### C
```
python
# 该函数的输出数据只含有 cloumn_one cloumn_two cloumn_three 三个列
def
create_dataframe_from_2darray
():
data
=
[
[
3
,
5
,
2
],
[
2
,
7
,
9
],
[
5
,
6
,
9
]
]
data_df
=
pd
.
DataFrame
(
data
,
columns
=
[
'cloumn_one'
,
'cloumn_two'
,
'cloumn_three'
])
return
data_df
```
data/3.python高阶/2.结构化数据分析工具Pandas/2.数据结构/dataframe.py
浏览文件 @
002675a9
...
@@ -7,45 +7,53 @@ import pandas as pd
...
@@ -7,45 +7,53 @@ import pandas as pd
import
numpy
as
np
import
numpy
as
np
def
create_dataframe
(
measure
):
def
create_dataframe_from_list
():
if
measure
==
1
:
data
=
{
print
(
'由数组list组成的字典创建dataframe:'
)
'cloumn_one'
:
np
.
random
.
randint
(
0
,
10
,
size
=
5
),
data
=
{
'cloumn_two'
:
np
.
random
.
randint
(
0
,
10
,
size
=
5
),
'cloumn_one'
:
np
.
random
.
randint
(
0
,
10
,
size
=
5
),
'cloumn_three'
:
np
.
random
.
randint
(
0
,
10
,
size
=
5
)
'cloumn_two'
:
np
.
random
.
randint
(
0
,
10
,
size
=
5
),
}
'cloumn_three'
:
np
.
random
.
randint
(
0
,
10
,
size
=
5
)
data_df
=
pd
.
DataFrame
(
data
)
}
return
data_df
data_df
=
pd
.
DataFrame
(
data
)
print
(
data_df
)
def
create_dataframe_from_series
():
elif
measure
==
2
:
data
=
{
print
(
'由Series组成的字典创建dataframe:'
)
'cloumn_one'
:
pd
.
Series
(
np
.
random
.
randint
(
0
,
10
,
size
=
5
)),
data
=
{
'cloumn_two'
:
pd
.
Series
(
np
.
random
.
randint
(
0
,
10
,
size
=
5
)),
'cloumn_one'
:
pd
.
Series
(
np
.
random
.
randint
(
0
,
10
,
size
=
5
)),
'cloumn_three'
:
pd
.
Series
(
np
.
random
.
randint
(
0
,
10
,
size
=
5
))
'cloumn_two'
:
pd
.
Series
(
np
.
random
.
randint
(
0
,
10
,
size
=
5
)),
}
'cloumn_three'
:
pd
.
Series
(
np
.
random
.
randint
(
0
,
10
,
size
=
5
))
data_df
=
pd
.
DataFrame
(
data
)
}
return
data_df
data_df
=
pd
.
DataFrame
(
data
)
print
(
data_df
)
elif
measure
==
3
:
def
create_dataframe_from_2darray
():
print
(
'通过二维数组直接创建dataframe:'
)
data
=
np
.
random
.
randint
(
0
,
10
,
size
=
9
).
reshape
(
3
,
3
)
data
=
np
.
random
.
randint
(
0
,
10
,
size
=
9
).
reshape
(
3
,
3
)
data_df
=
pd
.
DataFrame
(
data_df
=
pd
.
DataFrame
(
data
,
columns
=
[
'cloumn_one'
,
'cloumn_two'
,
'cloumn_three'
])
data
,
columns
=
[
'cloumn_one'
,
'cloumn_two'
,
'cloumn_three'
])
return
data_df
print
(
data_df
)
elif
measure
==
4
:
print
(
'由字典组成的列表创建dataframe:'
)
def
create_dataframe_from_dict
():
data
=
[{
'cloumn_one'
:
1
,
'cloumn_two'
:
2
,
'cloumn_three'
:
3
},
data
=
[{
'cloumn_one'
:
1
,
'cloumn_two'
:
2
,
'cloumn_three'
:
3
},
{
'cloumn_one'
:
5
,
'cloumn_two'
:
6
,
'cloumn_three'
:
7
}]
{
'cloumn_one'
:
5
,
'cloumn_two'
:
6
,
'cloumn_three'
:
7
}]
data_df
=
pd
.
DataFrame
(
data
)
data_df
=
pd
.
DataFrame
(
data
)
print
(
data_df
)
return
data_df
else
:
print
(
'该参数不支持,可选参数为1,2,3,4'
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
create_dataframe
(
1
)
print
(
'由数组list组成的字典创建dataframe:'
)
create_dataframe
(
2
)
data_df
=
create_dataframe_from_list
()
create_dataframe
(
3
)
print
(
data_df
)
create_dataframe
(
4
)
create_dataframe
(
0
)
print
(
'由Series组成的字典创建dataframe:'
)
data_df
=
create_dataframe_from_series
()
print
(
data_df
)
print
(
'通过二维数组直接创建dataframe:'
)
data_df
=
create_dataframe_from_2darray
()
print
(
data_df
)
print
(
'由字典组成的列表创建dataframe:'
)
data_df
=
create_dataframe_from_dict
()
print
(
data_df
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录