将包含数组的字典转换为以数组为字符串的DataFrame

时间:2020-04-30 19:07:23

标签: python pandas dataframe dictionary

我有一本这样的字典:

d = {name: 'A', 'numbers': array([2.72, 3.74, 1.75])}

我需要从此字典创建Pandas DataFrame。我目前正在使用df = pd.DataFrame.from_dict(d)

但是,DataFrame看起来像这样:

name    numbers
  A      2.72
  A      3.74
  A      1.75

我尝试使用df = pd.DataFrame(d),但得到了相同的结果。

由于我有一个包含一千多个值的数字数组,因此DataFrame中有很多重复的信息,对于我的预期目的并没有真正的用处。

我想要一个这样的DataFrame:

name    numbers
  A      "[2.72, 3.74, 1.75]"

1 个答案:

答案 0 :(得分:1)

这可以做到:

  name             numbers
0    A  [2.72, 3.74, 1.75]

输出:

private static final String URL_LIST_DRIVES = "https://graph.microsoft.com/v1.0/me/drives";
    private static final String URL_LIST_DRIVE_ITEMS = "https://graph.microsoft.com/v1.0/me/drives/%s/root/children";
    private static final String URL_LIST_FOLDER_ITEMS = "https://graph.microsoft.com/v1.0/me/drives/%s/items/%s/children";
    private static final String URL_ITEM_CONTENT = "https://graph.microsoft.com/v1.0/me/drives/%s/items/%s/content";
相关问题