【发布时间】:2022-01-26 10:45:31
【问题描述】:
我有一些记录的数据框。我需要合并所需的记录并分配给新变量并将其放入同一个数据框中。
import pandas as pd
df = pd.DataFrame({'temp_c': [17.0, 25.0]},
index=['Portland', 'Berkeley'])
df = df.assign(temp_f=df['temp_c'] * 9 / 5 + 32)
print(df)
输出:
预期输出:
temp_c temp_f new_type
portland 17.0 62.6 [{'temp_c': '17.0', 'temp_f': '62.6'}]
Berkley 25.0 77.0 [{'temp_c': '25.0', 'temp_f': '77.0'}]
【问题讨论】:
标签: python python-3.x pandas dataframe python-2.7