小编Ham*_*ait的帖子

熊猫与不同指数相结合

我有三个要连接的数据框,但是它们都有不同的索引。所有三个索引具有相同的长度。我的第一个df如下所示:

Index    Time_start    Time_end    duration    value
0        5             10          5           1.0
1        10            16          6           NaN
...
39       50            53          3           NaN
Run Code Online (Sandbox Code Playgroud)

第二个df如下所示:

Index    Time_start    Time_end    duration    value
40        5             10         5           2.0
42        10            16         6           NaN
...
79        50            53         3           NaN
Run Code Online (Sandbox Code Playgroud)

第三个看起来完全相同,但是Index = [80..119],但是time_start,Time_end和duration完全相同。价值各不相同。

我想连接值列,使它看起来像这样

Index    Time_start    Time_end    duration    value1    value2 value3
1        5             10          5           1.0       2      3
2        10            16          6           NaN       NaN    NaN
...
39       50            53          3           NaN       NaN    NaN
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经尝试过

pd.concat([df1, df2.value, …
Run Code Online (Sandbox Code Playgroud)

python concat dataframe pandas

4
推荐指数
1
解决办法
5094
查看次数

Update a dict values with values in a list

I have a dictionary I want to update:

my_dict = {"a":"A", "b":"B"}
Run Code Online (Sandbox Code Playgroud)

and a list with the exact same length:

my_list = ["D", "E"]
Run Code Online (Sandbox Code Playgroud)

I would like to find the most efficient way to update my_dict with the values from my_list to:

{"a":"D", "b":"E"}
Run Code Online (Sandbox Code Playgroud)

without having to run multiple for loops or similar. I tried to do this with list comprehensions, but it does not allow multiple statements:

{my_dict_key:list_item for my_dict_key in my_dict.keys(), list_item in my_list}
Run Code Online (Sandbox Code Playgroud)

python dictionary list

1
推荐指数
1
解决办法
74
查看次数

标签 统计

python ×2

concat ×1

dataframe ×1

dictionary ×1

list ×1

pandas ×1