我正在尝试捕获进入熊猫数据帧的空列表,但发生上述错误:
ValueError:传递的值的形状为(1,5),索引表示(5,5)
我目前在这里有一个简单的设置:
if not daily_info:
daily_info= ["No data found today","No data found today","No data found today","No data found today","No data found today"]
df = pd.DataFrame(data=daily_info, columns=['Send/Collect', 'Hospital', 'Courier', 'Kit', 'Manufacturer'])
df = df.assign(Status="Not Started")
这似乎与this类似,它询问是否要添加现有的DF,但是答案并不能真正帮助我解决不同的情况。
有人可以帮我弄清楚我哪里出错了吗?
答案 0 :(得分:1)
我认为需要将嵌套list
传递给DataFrame
构造函数-[daily_info]
:
daily_info= ["No data found today","No data found today","No data found today","No data found today","No data found today"]
df = pd.DataFrame(data=[daily_info], columns=['Send/Collect', 'Hospital', 'Courier', 'Kit', 'Manufacturer'])
df = df.assign(Status="Not Started")
print (df)
Send/Collect Hospital Courier \
0 No data found today No data found today No data found today
Kit Manufacturer Status
0 No data found today No data found today Not Started