我有一个数字的简单数据框,我想找到它的数字根,也可以作为一个数据帧
我使用的代码寻找数字根源
def digital_root (n):
ap = 0
n = abs(int(n))
while n >= 10:
n = sum(int(digit) for digit in str(n))
ap += 1
return n
和我写的代码是
for i in range(0, 24):
for w in range(0, len(w_24)):
column = []
a = w_24.iloc[w:i]
df = a.to_string()
x = digital_root(df)
column.append(x)
w_dr = pd.DataFrame(list(column.items()), columns = ['i'])
我收到以下错误:
ValueError: invalid literal for int() with base 10: 'Empty DataFrame\nColumns
关于如何执行此任务有什么建议?
谢谢
你digital_root期待一个int。
你给它一个字符串
df = a.to_string()
x = digital_root(df)
你不是打算发送a = w_24.iloc[w, i]
呢?注意iloc[w, i]
不iloc[w:i]
,所述第一轴的轴2不索引片