为了账号安全,请及时绑定邮箱和手机立即绑定

在生成第三个表格时报错是怎么回事?

 df=pd.DataFrame({"A":1,"B":pd.Timestamp("20170301","C":pd.Series(1,index=list(range(4)),dtype="float32"),"D":np.array([3]*4,dtype="float32"),"E":pd.Categorical(["police","student","teacher","doctor"])})                                                       ^

SyntaxError: invalid syntax

"C":pd.Series(1,index=list(range(4)),dtype="float32"),一段显示“variables annotation cannot be combined with tuple unpacking”

正在回答

1 回答

建议在pycharm里编写,方便debug


很明显你的这段代码是在这里有错:

B":pd.Timestamp("20170301","C":

应该修改为:

B":pd.Timestamp("20170301"),"C":

建议用pycharm编写,方便debug

这一段正确的代码应该是这样的:

df = pd.DataFrame({ "A": 1,
                    "B": pd.Timestamp("20170301"),
                    "C": pd.Series(1, index=list(range(4)), dtype="float"),
                    "D": np.array([3] * 4, dtype="float32"),
                    "E": pd.Categorical(["police", "student", "teacher", "doctor"])})


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

在生成第三个表格时报错是怎么回事?

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号