Mit Python Tabelle erstellen und erste Zeile farblich gestalten
Verfasst: Dienstag 19. Juni 2018, 12:03
Hallo zusammen, ich habe ein Python Code mit Pandas und Matplotlib geschrieben und wollte eine Excel Datei einlesen und diese als Tabelle plotten. Soweit funktioniert es auch, nur kann ich es nicht farblich ändern. Ich wollte die erste Zeile farblich hervorheben, damit es übersichtlicher ist. Damit man ein Überblick hat, habe ich mein Code unten aufgelistet mit Fehler Code:
Und hier die Fehlerbeschreibung:
Code: Alles auswählen
import matplotlib.pyplot as plt
import pandas as pd
from pandas.plotting import table
#first_page
DATA_FILE = "C:/test/corr.xlsx"
df = pd.read_excel("C:/test/corr.xlsx")
s = df.iloc[0:15, 0:10]
fig, ax = plt.subplots(figsize=(5, 1))
plt.suptitle("1.Excel-Daten", fontsize =15)
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
ax.set_frame_on(False)
tabla = table(ax, s, colWidths=[0.30]*len(df.columns), rowColours='r')
tabla.auto_set_font_size(False)
tabla.set_fontsize(15)
tabla.scale(1.5,1.5)
plt.show
Und hier die Fehlerbeschreibung:
Code: Alles auswählen
runfile('C:/Users/ucarm.lokal/.spyder-py3/untitled17.py', wdir='C:/Users/ucarm.lokal/.spyder-py3')
Traceback (most recent call last):
File "<ipython-input-6-567501243038>", line 1, in <module>
runfile('C:/Users/ucarm.lokal/.spyder-py3/untitled17.py', wdir='C:/Users/ucarm.lokal/.spyder-py3')
File "C:\Anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "C:\Anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/ucarm.lokal/.spyder-py3/untitled17.py", line 25, in <module>
tabla = table(ax, s, colWidths=[0.30]*len(df.columns), rowColours='r', colColours = 'r')
File "C:\Anaconda\lib\site-packages\pandas\plotting\_tools.py", line 65, in table
colLabels=colLabels, **kwargs)
File "C:\Anaconda\lib\site-packages\matplotlib\table.py", line 652, in table
text=colLabels[col], facecolor=colColours[col],
IndexError: string index out of range