Tabelo lahko enostavno pretvoriš iz excelove tabele v Markdown z:
https://thisdavej.com/copy-table-in-excel-and-paste-as-a-markdown-table/
WIDE Tabela:
ID | TimeStamp | A | B | C |
---|---|---|---|---|
1 | 12.05.2019 11:34 | 0 | 3 | 5 |
2 | 12.05.2019 12:34 | 1 | 1 | 3 |
3 | 12.05.2019 13:34 | 0 | 0 | 3 |
LONG Tabela:
ID | TimeStamp | Atribut | Vrednost |
---|---|---|---|
1 | 12.05.2019 11:34 | A | 0 |
1 | 12.05.2019 11:34 | B | 3 |
1 | 12.05.2019 11:34 | C | 5 |
2 | 12.05.2019 12:34 | A | 1 |
2 | 12.05.2019 12:34 | B | 1 |
2 | 12.05.2019 12:34 | C | 3 |
3 | 12.05.2019 13:34 | A | 0 |
3 | 12.05.2019 13:34 | B | 0 |
3 | 12.05.2019 13:34 | C | 3 |
#podatke so kopiram kar iz excelove tabele
import pandas as pd
df_w = pd.read_clipboard()
print(df_w)
#lahko bi naredil df_w kar tukaj:
df_w = pd.DataFrame({
'ID': [1, 2, 3],
'TimeStamp': ['12.05.2019 11:34', '12.05.2019 12:34', '12.05.2019 13:34'],
'A': [0, 1, 0],
'B': [3, 1, 0],
'C': [5, 3, 3]
})
print(pdf_w)
df_w = df_w.set_index(['ID', 'TimeStamp'])
print(df_w)
df_w = df_w.reset_index()
print(df_w)
#TO JE PRETVORBA iz WIDE v LONG
df_l = pd.melt(df_w, id_vars = ['ID', 'TimeStamp']) # pd.melt(df_w, id_vars = ['ID', 'TimeStamp'], value_vars = ['A','B','C'])
print(df_l)
nazaj v excel kopiram z:
df_l.to_clipboard(excel=True)
#Za lepsi prikaz
from IPython.display import display, HTML
HTML(df_l.to_html())