在这里,我想将 2 列数据框转换为新系列。“max”应该是索引,“price”是新系列的值。怎么做 ?我下面使用的方式似乎不正确: pd.Series(a['max'], index=a['price'])
>>> a
price max
0 4.0 86
1 5.0 87
2 6.0 88
3 7.0 91
4 8.0 91
.. ... ...
385 1900.0 98
386 2000.0 97
387 2013.0 91
388 2500.0 96
389 3300.0 88
[390 rows x 2 columns]
>>> type(a)
<class 'pandas.core.frame.DataFrame'>
Run Code Online (Sandbox Code Playgroud) 我想生成一个包含字典的列表。在每个字典中,键都是固定的,值是从循环中输入的。
格式如下:
mylist = [{'name': 'test101', 'status': '30'}, {'name': 'test102', 'status': '90'}]
Run Code Online (Sandbox Code Playgroud)
但是,for loop仅遍历列表,这不是我想要的。如何生成词典列表?
mylist = [{'name': 'test101', 'status': '30'}, {'name': 'test102', 'status': '90'}]
Run Code Online (Sandbox Code Playgroud)