使用json文件输入附加列堆栈

2024-08-31 10:57:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个json文件

 {  "teams":{
    "0":"Liverpool",
    "1":"Liverpool",
    "2":"Arsenal",
    "3":"City",
    "4":"Watford",
    "5":"Liverpool",
    "6":"Chelsea"
 }
}

代码:

df = pd.read_csv("clubs.csv")
clubs_df= pd.read_json('domain.json')

clubs =pd.DataFrame.from_dict(clubs_df)  

df = df.stack()
df = df.append(clubs)
df = df.value_counts()
df = df.reset_index()
print(df)

如果我尝试将这些值添加到堆栈中,则会出现以下错误:TypeError: to_append should be a Series or list/tuple of Series, got DataFrame