我有流派的数据框
df = pd.DataFrame({'genres': [['Drama'], ['Music', 'Drama', 'Romance'],
['Action', 'Adventure', 'Comedy'],
['Thriller', 'Romance', 'Drama'],
['Adventure', 'Family']]
})
print(df)
genres = ['Action', 'Adventure', 'Comedy', 'Drama', 'Family', 'Music', 'Romance', 'Thriller'] # list of all genres
Run Code Online (Sandbox Code Playgroud)
数据:
genres
0 [Drama]
1 [Music, Drama, Romance]
2 [Action, Adventure, Comedy]
3 [Thriller, Romance, Drama]
4 [Adventure, Family]
Run Code Online (Sandbox Code Playgroud)
我希望输出像:
genres Action Adventure Comedy Drama Family \
0 [Drama] 0 0 0 1 0
1 [Music, Drama, Romance] 0 0 0 1 0
2 [Action, Adventure, Comedy] …Run Code Online (Sandbox Code Playgroud) 我有以下数据集:
import datetime
import pandas as pd
df = pd.DataFrame({'PORTFOLIO': ['A', 'A', 'A', 'A','A', 'A', 'A', 'A','A', 'A','A', 'A', 'A', 'A'],
'DATE': ['28-02-2018','31-03-2018','30-04-2018','31-05-2018','30-06-2018','31-07-2018','31-08-2018',
'30-09-2018','31-10-2018','30-11-2018','31-12-2018','31-01-2019','28-02-2019','05-03-2019'],
'IRR': [.7, .8, .9, .4, .2, .3, .4, .9, .7, .8, .9, .4,.7, .8],
})
df
PORTFOLIO DATE IRR
0 A 2018-02-28 0.7
1 A 2018-03-31 0.8
2 A 2018-04-30 0.9
3 A 2018-05-31 0.4
4 A 2018-06-30 0.2
5 A 2018-07-31 0.3
6 A 2018-08-31 0.4
7 A 2018-09-30 0.9
8 A 2018-10-31 0.7
9 …Run Code Online (Sandbox Code Playgroud) 挑战:找到可从包含5个元素的列表中的四个元素中获得的最小和最大总和.
接下来的方法:按降序和升序对列表进行排序,并将它们存储到两个不同的变量中.找到两个列表中前4个元素的总和.一个总和是最小的,第二个是最大的.
代码:
arr = [2,1,3,4,5]
arr.sort()
asc = arr
print(asc[0],asc[1],asc[2],asc[3])
arr.sort(reverse = True)
des = arr
print(des[0],des[1],des[2],des[3])
maxi = 0
mini = 0
for j in range(4) :
mini = mini + asc[j]
print(mini, asc[j])
maxi = maxi + des[j]
print(maxi,des[j])
print(mini, maxi)
Run Code Online (Sandbox Code Playgroud)
这里引入的打印语句很少用于调试目的.在代码中可见,bot在进入for循环之前和进入循环之后打印已排序的版本.如输出中所见,它清晰可见,应该按升序保持元素的列表具有降序的元素.
输出:
11 12 13 14 - list in the ascending order
15 14 13 12 - list in the descending order
15 15 - round 0
15 15
29 14 - round 1
29 14 …Run Code Online (Sandbox Code Playgroud) 我需要时间序列方面的帮助。我有这个用熊猫构建的数据框:
date bitcoin tether
91 2017-11-01 0.0444 0.0001
90 2017-11-02 0.0426 0.0000
89 2017-11-03 0.0181 0.0000
88 2017-11-04 0.0296 0.0000
87 2017-11-05 0.0035 0.0000
86 2017-11-06 -0.0582 0.0000
85 2017-11-07 0.0206 0.0000
84 2017-11-08 0.0481 0.0100
Run Code Online (Sandbox Code Playgroud)
我想在同一个图中绘制系绳和比特币的运动,并且时间应该在 x 轴上可视化。我希望比特币和 Tether 能够按自己的大小进行缩放。我想在图片中有这样的东西(用 matplotlib 创建),但时间显示在轴上。我不关心包,只关心结果......我使用的是 Python 2.7。
Tether vs 比特币 Var%
这是一个课程分配代理,可以帮助从目录中使用过滤器课程.用户可以选择"主要","学期"等标准,这就是为什么我把它作为一个elif声明.elif在跑步时没有工作; 当用户选择"学期"时,它会显示"主要"的内容.代码是:
while True:
print("What kind of courses are you looking for? ")
Courses = {1: {'Course': 'Interaction Design', 'Major': 'HCD', 'Semester': 'ODD', 'Cycle': '1', 'Level': '1', 'Time': 'AM', 'Days': 'MT', 'Credits': '2', 'Pre-reqesite': 'None'},
2: {'Course': 'Colour and Texture', 'Major': 'IADP', 'Semester': 'ODD', 'Cycle': '1', 'Level': '1', 'Time': 'AM', 'Days': 'THF', 'Credits': '2', 'Pre-reqesite': 'None'},
3: {'Course': 'Basics of Service Design', 'Major': 'BSSD', 'Semester': 'ODD', 'Cycle': '2', 'Level': '1', 'Time': 'PM', 'Days': 'THF', 'Credits': '2', 'Pre-reqesite': 'None'},
4: {'Course': …Run Code Online (Sandbox Code Playgroud) python ×5
pandas ×3
dataframe ×2
arrays ×1
date ×1
matplotlib ×1
python-2.7 ×1
python-3.x ×1
sorting ×1