小编Tou*_*han的帖子

如何在列中为 numpy 数组添加标签

如何在列中添加标签作为 numpy 数组的字符串

我需要这个输出

   One Two Three 
A   1,  2,  3  
B   4,  5,  6  
Run Code Online (Sandbox Code Playgroud)
import numpy as np
import pandas as pd
a=pd.DataFrame.from_items([('A', [1, 2, 3]), ('B', [4, 5, 6])],
orient='index', columns=['one', 'two', 'three'])
print(a)
Run Code Online (Sandbox Code Playgroud)

当我使用这段代码时,代码给了我正确的结果,但也给了我一个错误;我不明白。

注意:我不明白这一行

a=pd.DataFrame.from_items([('A', [1, 2, 3]), ('B', [4, 5, 6])],
    orient='index', columns=['one', 'two', 'three'])
Run Code Online (Sandbox Code Playgroud)

我需要另一种方法来实现这一点。

输出:

    one  two  three 
A    1    2      3
B    4    5      6
C:\Users\Toufik\Anaconda3\lib\site-packages\ipykernel_launcher.py:4:
FutureWarning: from_items is deprecated. Please use
DataFrame.from_dict(dict(items), ...) instead.
DataFrame.from_dict(OrderedDict(items)) may be used to preserve the …
Run Code Online (Sandbox Code Playgroud)

python numpy pandas

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

标签 统计

numpy ×1

pandas ×1

python ×1