如何将数据帧添加为 python 中的列?
How to add DataFrames as columns in python?
当我使用附加功能时,一个数据框出现在另一个数据框的下方,但我希望它们并排放置。怎么做?我说的是 (Colour_Features) 输出在图像中。
import pandas as pd
red_data = pd.DataFrame([[255,0,20],[210,30,0],[220,40,5],[240,10,30],[225,60,20]])
green_data = pd.DataFrame([[0,255,0],[10,240,5],[0,240,20],[5,220,30],[30,230,10]])
blue_data = pd.DataFrame([[30,10,220],[10,10,255],[0,0,240],[25,15,210],[0,20,220]])
red_data.columns =["R","G","B"]
green_data.columns =["R","G","B"]
blue_data.columns =["R","G","B"]
print(red_data)
print(green_data)
print(blue_data)
Feature1 = red_data.loc[:,"R"]-red_data.loc[:,"G"]
Feature2 = 2*red_data.loc[:,"B"] - red_data.loc [:,"R"] - red_data.loc [:,"G"]
print(Feature1)
print(Feature2)
Colour_Features= pd.DataFrame([[]])
Colour_Features=Feature1.append(Feature2)
print (Colour_Features)
沿轴 1(列)连接数据帧。
Colour_Features=pd.concat([Feature1, Feature2], axis=1)
print (Colour_Features)
0 1
0 255 -215
1 180 -240
2 180 -250
3 230 -190
4 165 -245
当我使用附加功能时,一个数据框出现在另一个数据框的下方,但我希望它们并排放置。怎么做?我说的是 (Colour_Features) 输出在图像中。
import pandas as pd
red_data = pd.DataFrame([[255,0,20],[210,30,0],[220,40,5],[240,10,30],[225,60,20]])
green_data = pd.DataFrame([[0,255,0],[10,240,5],[0,240,20],[5,220,30],[30,230,10]])
blue_data = pd.DataFrame([[30,10,220],[10,10,255],[0,0,240],[25,15,210],[0,20,220]])
red_data.columns =["R","G","B"]
green_data.columns =["R","G","B"]
blue_data.columns =["R","G","B"]
print(red_data)
print(green_data)
print(blue_data)
Feature1 = red_data.loc[:,"R"]-red_data.loc[:,"G"]
Feature2 = 2*red_data.loc[:,"B"] - red_data.loc [:,"R"] - red_data.loc [:,"G"]
print(Feature1)
print(Feature2)
Colour_Features= pd.DataFrame([[]])
Colour_Features=Feature1.append(Feature2)
print (Colour_Features)
沿轴 1(列)连接数据帧。
Colour_Features=pd.concat([Feature1, Feature2], axis=1)
print (Colour_Features)
0 1
0 255 -215
1 180 -240
2 180 -250
3 230 -190
4 165 -245