I am trying to create a pandas df that looks like:
AAA BBB CCC
0 4 10 100
1 4 20 50
2 5 30 -30
3 5 40 -50
To implement, I am for now creating two dataframes
df1 = pd.DataFrame({'AAA' : [4] * 2 , 'BBB' : [10,20], 'CCC' : [100,50]})
df2 = pd.DataFrame({'AAA': [5]*2, 'BBB' : [30,40],'CCC' : [-30,-50]})
and then appending rows of df2 to df1 to create the desired df
I tried to do
df = pd.DataFrame({'AAA' : [4] * 2, 'AAA': [5]*2, 'BBB' :
[10,20,30,40],'CCC' : [100,50,-30,-50]}); df
But I get an error with the key message:
ValueError('arrays must all be same length') ValueError: arrays must all be the same length
I can of course do:
df = pd.DataFrame({'AAA' : [4,4,5,5], 'BBB' : [10,20,30,40],'CCC' :
[100,50,-30,-50]}); df
But is there not another elegant way to do this? This small example is easy to implement but if I want to scale up to many rows, the input becomes very long.