我有两个数据框作为流:
leader:
0 11
1 8
2 5
3 9
4 8
5 6
[6065 rows x 2 columns]
DatasetLabel:
Unnamed: 0 0 1 .... 7 8 9 10 11 12
0 A J .... 1 2 5 NaN NaN NaN
1 B K .... 3 4 NaN NaN NaN NaN
[4095 rows x 14 columns]
Run Code Online (Sandbox Code Playgroud)
信息数据集的列名称0到6是关于数据的DatasetLabel,而7到12是引用领导者Dataframe的第一列的索引。
我想创建一个数据集,而不是DatasetLabel Dataset中的索引,而是从leader数据集中获取每个索引的值,即 leader.iloc[index,1]
我该如何使用python功能?
输出应如下所示:
DatasetLabel:
Unnamed: 0 0 1 .... 7 8 9 10 11 12
0 A J .... 8 5 …
Run Code Online (Sandbox Code Playgroud) 当我运行这个玩具代码时
test = pd.DataFrame({'a': [1, 2, 3, 4]})
test['b'] = ''
for i in range(len(test)):
test['b'].loc[i] = [5, 6, 7]
Run Code Online (Sandbox Code Playgroud)
我有一个警告
SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self._setitem_single_block(indexer, value, name)
Run Code Online (Sandbox Code Playgroud)
loc
但如果我按照这种方法使用
test = pd.DataFrame({'a': [1, 2, 3, 4]})
test['b'] = ''
for i in range(len(test)):
test.loc[i, 'b'] = [5, 6, 7]
Run Code Online (Sandbox Code Playgroud)
我收到一个错误
ValueError: Must have equal len keys and …
Run Code Online (Sandbox Code Playgroud)