Home > database >  How to insert a dataframe 20x1 into a dataframe 1x8
How to insert a dataframe 20x1 into a dataframe 1x8

Time:01-30

I have been trying to accomplish the following problem. There are dataframe 20x1 and another one 1x7. But after i tried to join both, i get a error returning NaN values.

  1. mean_control_chart it's the dataframe 1x7
  2. x_barra was a series, but a convert to a dict and after to a dataframe 20x1
  1. mean_control_chart dataframe:

enter image description here

  1. x_barra dataframe:

enter image description here

Code:

mean_control_chart = pd.DataFrame(df_mean_control_chart)
x_barra_dict = x_barra.to_dict()
x_barra_df = pd.DataFrame(x_barra_dict, index=['X-Barra']) 
x_barra_df = x_barra_df.transpose() 
mean_control_chart['X_Barra'] = x_barra_df

The error i get:

OBS: I want after that, the data at the 7 columns of mean_control_chart repet itself based of the x_barra len of rows. So if there are 20 or 100 lines in x_barra, the lines of mean_control_chart would repeat 20 or 100

CodePudding user response:

Please never post dataframes as pictures, always as text: How to make good reproducible pandas examples

As to your question, cross merge is probably the easiest. Demonstrating on a simple example (here dataframes provided by you would be useful):

df1 = pd.DataFrame(columns = list('ABCD'), data = [[1,2,3,4]])
df2 = pd.DataFrame(columns = ['E'], data= [[5],[6],[7],[8],[9]])
df1.merge(df2, how = 'cross')

output


    A   B   C   D   E
0   1   2   3   4   5
1   1   2   3   4   6
2   1   2   3   4   7
3   1   2   3   4   8
4   1   2   3   4   9
  •  Tags:  
  • Related