記錄在項目中遇到的一些問題。
import numpy as np
a = np.array((0.2,0.5,0.9,1.5))
對a進行轉置:
import numpy as np
a = np.array((0.2,0.5,0.9,1.5))
a_new = a.reshape(1,4)
import numpy as np
import pandas as pd
a = np.array((0.2,0.5,0.9,1.5))
a_new = a.reshape(1,4)
df_a = pd.DataFrame(a_new)
修改列名:
import numpy as np
import pandas as pd
a = np.array((0.2,0.5,0.9,1.5))
a_new = a.reshape(1,4)
df_a = pd.DataFrame(a_new)
df_a.columns = ['a', 'b', 'c', 'd'] # 列名
import numpy as np
import pandas as pd
a = np.array((0.2,0.5,0.9,1.5))
a_new = a.reshape(1,4)
df_a = pd.DataFrame(a_new)
df_a.columns = ['a', 'b', 'c', 'd'] # 列名
# DataFrame轉jason
df_a_new = df_a.to_json(orient="columns")
在df_a中列的順序是a、b、c、d
現在需要的順序是d、b、c、a
import numpy as np
import pandas as pd
a = np.array((0.2,0.5,0.9,1.5))
a_new = a.reshape(1,4)
df_a = pd.DataFrame(a_new)
df_a.columns = ['a', 'b', 'c', 'd'] # 列名
df_a_p = df_a[["d","b","c","a"]]
附,贈送一個
拼接DataFrame,A,B,C, D四個DataFrame
ABCD = pd.concat([A,B,C, D], axis=1)
參考:
https://blog.csdn.net/qq_27328197/article/details/113823989
p{margin:10px 0}.markdown-body
The first lesson : Dont ask th