84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
表结构如下:
date,a,b,c0101,1,2,30202,4,5,6
要转换成:
date,col1,col20101,a,10202,a,40101,b,20202,b,50101,c,30202,c,6
想了很久,不知道该如何去写。使用Python的pandas和sql都可以,十分感谢!
About the conversion problem of a table in SQL-PHP Chinese website Q&A-About the conversion problem of a table in SQL-PHP Chinese website Q&A
Look around and learn.
可以用pandas的melt方法
a = pd.DataFrame([[0101,1,2,3],[0202,4,5,6]],columns=['date','a','b','c'])date a b c0 65 1 2 31 130 4 5 6pd.melt(a,id_vars=['date'],var_name='col1',value_name='col2')
date col1 col20 65 a 11 130 a 42 65 b 23 130 b 54 65 c 35 130 c 6
About the conversion problem of a table in SQL-PHP Chinese website Q&A-About the conversion problem of a table in SQL-PHP Chinese website Q&A
Look around and learn.
可以用pandas的melt方法
a = pd.DataFrame([[0101,1,2,3],[0202,4,5,6]],columns=['date','a','b','c'])
date a b c0 65 1 2 31 130 4 5 6
pd.melt(a,id_vars=['date'],var_name='col1',value_name='col2')
date col1 col20 65 a 11 130 a 42 65 b 23 130 b 54 65 c 35 130 c 6