如何在列中添加标签作为 numpy 数组的字符串
我需要这个输出
Run Code Online (Sandbox Code Playgroud)One Two Three A 1, 2, 3 B 4, 5, 6
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)
我需要另一种方法来实现这一点。
输出:
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 …