pandas 我有一个数据框,有两列A和B,现在,如何将数据框值存储在列表中,并用逗号和括号分隔它们?

xzlaal3s  于 2023-08-01  发布在  其他
关注(0)|答案(2)|浏览(89)

我有以下 Dataframe

import pandas as pd
data = [[0.8,0.23], [0.3,.40], [0.6,0.8], [0.7,0.9]]
df = pd.DataFrame(data, columns=['A','B'])
df

字符串
我的预期输出是

List= [(0.8,0.23), (0.3,.40), (0.6,0.8), (0.7,0.9)]

l2osamch

l2osamch1#

替代方法:

data = [[0.8,0.23], [0.3,.40], [0.6,0.8], [0.7,0.9]]
df = pd.DataFrame(data, columns=['A','B'])

lst = [tuple(df.loc[x]) for x in df.index]
print(lst)

字符串

f1tvaqid

f1tvaqid2#

to_record()方法
尝试使用它:

data_list = list(df.to_records(index=False))
print(data_list)

字符串

相关问题