在生成第三個表格時報錯是怎么回事?
?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”
2019-09-11
建議在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"])})