我想要做的是在标题中解释得很清楚,但为了更好地衡量,我的问题是:
为了这个例子,假设我有一个包含36个问题的Google表单,我想使用Python 3来处理数据格式的那一行答案。问题是我得到了一个错误,但我已经超越了我自己。以下是我尝试过的:
from flask import Flask, render_template, request
import pandas as pd
import numpy as np
io_table=pd.DataFrame(np.random.random_sample((1,36)))
fctr_column=pd.DataFrame(np.random.random_sample((6)))
io_table=pd.DataFrame(io_table) #Convert list to DataFrame
io_t=io_table
factor=fctr_column
test=pd.DataFrame()
for i in range(0,io_table.shape[1]+1):
test=io_table.loc[0,i+1:i+6], ignore_index=True
i=i+6
print(test)正如我之前提到的,我犯了一个错误:
File "path/to/temp.py", line 29, in <module>
test=io_table.loc[0,i+1:i+6], ignore_index=True
TypeError: cannot unpack non-iterable bool object现在我不知道该怎么办了。有人能提供解决方案吗?
编辑:预期输入和输出

发布于 2018-10-10 09:12:49
不确定我是否正确,但如果您有一个具有36个值的DataFrame,您可以使用以下示例对其进行整形:
import pandas as pd
a = range(1, 37)
df = pd.DataFrame(a).T
df.values.reshape((6,6))
#[[ 1 2 3 4 5 6]
# [ 7 8 9 10 11 12]
# [13 14 15 16 17 18]
# [19 20 21 22 23 24]
# [25 26 27 28 29 30]
# [31 32 33 34 35 36]]https://stackoverflow.com/questions/52721889
复制相似问题