我正在尝试从数据库创建 CSV 文件。所有文件都位于同一目录中。我有这个代码:
import pandas
data = pandas.read_csv("2018_Central_Park_Squirrel_Census_-_Squirrel_Data.csv")
grey_squirrels_count = len(data[data["Primary Fur Color"] == "Gray"])
red_squirrels_count = len(data[data["Primary Fur Color"] == "Cinnamon"])
black_squirrels_count = len(data[data["Primary Fur Color"] == "Black"])
print(grey_squirrels_count)
print(red_squirrels_count)
print(black_squirrels_count)
data_dict = {
"Fur Color": ["Gray", "Cinnamon", "Black"],
"Count": [grey_squirrels_count, red_squirrels_count, black_squirrels_count]
}
print(data_dict)
df = pandas.DataFrame(data_dict)
print(df)
df.to_csv("squirrel_count.csv")
但我收到此错误:
出了什么问题,如何解决?