我尝试使用Python的.pivot_table来转动CSV。我导入了正确的模块:
# Import modules
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
我已阅读我的csv文件:
training_tracker = pd.read_csv('Training Tracker_v02.csv')
我已经实现了.pivot_table:
pivot_test = training_tracker.pivot_table(index=['POD', 'Name', 'Date
Start', 'Date Finish', 'Total Days', 'Training Status', 'Exam Needed'],
columns='Training', values='DemoA')
然而,当我运行程序时,我收到以下错误:
Traceback (most recent call last):
File "C:/Users/PycharmProjects/training tracker/app1.py", line 33, in <module>
columns='Training', values='DemoA')
File "C:\Users\PycharmProjects\training tracker\venv\lib\site-packages\pandas\core\frame.py", line 4468, in pivot_table
margins_name=margins_name)
File "C:\Users\PycharmProjects\training tracker\venv\lib\site-packages\pandas\core\reshape\pivot.py", line 58, in pivot_table
raise KeyError(i)
KeyError: 'DemoA'
我的文件导入正常,因为我可以导入和读取它。我想要做的就是转动专栏&#39; Training&#39;并将其内容分成不同的列。我已经在索引中标记了我没有用的列。
任何帮助都会非常感激。
谢谢, 贝。