在我的pandas数据框中,我从csv加载了下表,称之为 table.csv
x | w | y | z
indexval1 | stringval1 | b1 | c1
indexval2 | stringval2 | b2 | c2
indexval3 | stringval3 | b3 | c3
indexval4 | stringval4 | b4 | c4
这是我运行的代码......
df = pandas.read_csv("table.csv")
df.pivot_table(values = ["y", "z"] index = "x" columns = "w")
df.fillna(value = 00)
看起来像这样:
----- | y | z | y | z
w |stringval1 | stringval1 | stringval2 | stringval2
x | | | |
indexval1| b1 | c1 | 00 | 00
indexval2| 00 | 00 | b2 | c2
indexval3| 00 | 00 | 00 | 0
indexval4| 00 | 00 | 00 | 00
如何编辑它看起来像这样:
w |stringval1 | stringval1 | stringval2 | stringval2
----- | y | z | y | z
x | | | |
indexval1| b1 | c1 | 00 | 00
indexval2| 00 | 00 | b2 | c2
indexval3| 00 | 00 | 00 | 0
indexval4| 00 | 00 | 00 | 00