[英]How to Add a Row of Values from One DF to Another
I'm trying to iterate through the table, and copy/append a row to another table based on its' column value.我正在尝试遍历表,并根据其列值将一行复制/附加到另一个表。 So if the value in the 3rd column is -1, the entire row is copied to another table (t_neg1).因此,如果第 3 列中的值为 -1,则将整行复制到另一个表 (t_neg1)。
cluster_table = clusters
table = [cluster_table, Label]
cluster_table = pd.concat(table, axis = 1, sort = False)
col = list(["X", "Y", "Cluster ID"])
# This part below here is causing me issues.
t_neg1 = pd.DataFrame()
t_0 = pd.DataFrame()
# I'm sures there's a better way to handle this but I'll look into it later
i = 0
for i in range(len(cluster_table)):
if cluster_table['Cluster ID'].loc == -1:
t_neg1.copy(cluster_table.loc[i])
if cluster_table['Cluster ID'].loc == 0:
t_0.copy(cluster_table.loc[i])
i += 1
print(t_neg1)
Can someone look at my code and tell me what I'm doing wrong.有人可以看看我的代码并告诉我我做错了什么。
Your code is not complete but still it looks like you are looking for this:您的代码不完整,但看起来您正在寻找这个:
for n, i in enumerate(fcma):
value = (i - min) / (max - min)
fcma[n] =value
value = (i - min) / (max - min)值 = (i - min) / (max - min)
Here min & max are 'builtin_function_or_method' not values(int/float/double).这里的最小值和最大值是“builtin_function_or_method”而不是值(int/float/double)。 Hence operation '-' has wrong operands of wrong types.因此操作“-”有错误类型的错误操作数。
According to your need at hand, first assign values to min & max, then you can use as is.根据您手头的需要,首先为最小值和最大值分配值,然后您可以按原样使用。 to到
In Python there is no builtin data type column
, so you should give us an example.在 Python 中没有内置数据类型column
,所以你应该给我们一个例子。
As the error message suggests, you are are doing something wrong
with Python builtins.正如错误消息所暗示的那样,您在使用 Python 内置函数时wrong
了什么。
min
and max
are Python functions - you cannot add or subtract them. min
和max
是 Python 函数——你不能对它们进行加减。
While it is possible to redeclare min
and max
, please do not do this - as exactly these kind of errors can happen.虽然可以重新声明min
和max
,但请不要这样做 - 因为正是这些类型的错误可能会发生。
If you cannot find a better name, please use min_
and max_
- appending an underscore to prevent shadowing builtins is common Python practice.如果找不到更好的名称,请使用min_
和max_
- 添加下划线以防止隐藏内置函数是常见的 Python 做法。
You're using min
and max
as variable names but they are Built-in functions.您使用min
和max
作为变量名,但它们是内置函数。 Try to rename your's variables.尝试重命名您的变量。
https://www.geeksforgeeks.org/max-min-python/ https://www.geeksforgeeks.org/max-min-python/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.