Home > Software engineering >  Not seeing all values of list when I create a dataframe from list
Not seeing all values of list when I create a dataframe from list

Time:04-10

I am using VerticaPy - enter image description here

test_vdf = read_csv("test.csv")
test_vdf

enter image description here

I then create a combined list and create a pandas dataframe from it

combine = [train_vdf, test_vdf] #gives a list
combine_pdf = pd.DataFrame(combine)
combine_pdf

But the output doesn't show the combined data from the two vDataFramess

enter image description here

Why don't I see the combined data in a table?

CodePudding user response:

Change to concat

combine_pdf = pd.concat(combine)

CodePudding user response:

If you are trying to create a dataframe with a combination of the columns in both input dataframes and row count equal to the sum of the row counts for each input, you can do this:

import pandas as pd
train_vdf = pd.DataFrame({
    'PassengerId' : [1,2],
    'Survived' : [0,1],
    'Pclass' : [3,1],
    'Name' : ['Braund, Mr. Owen Harris', 'Cumings, Mrs. John Bradley'],
    'Sex' : ['male', 'female'],
    'Age' : [22.0, 38.0]
})
test_vdf = pd.DataFrame({
    'PassengerId' : [895,896],
    'Pclass' : [3,3],
    'Name' : ['Wirz, Mr. Albert', 'Hirvonen, Mrs. Alexander'],
    'Sex' : ['male', 'female'],
    'Age' : [27.0, 22.0],
    'SibSp' : [0, 1]
})
df = pd.concat([train_vdf, test_vdf], ignore_index=True)
print(df)

Output:

   PassengerId  Survived  Pclass                        Name     Sex   Age  SibSp
0            1       0.0       3     Braund, Mr. Owen Harris    male  22.0    NaN
1            2       1.0       1  Cumings, Mrs. John Bradley  female  38.0    NaN
2          895       NaN       3            Wirz, Mr. Albert    male  27.0    0.0
3          896       NaN       3    Hirvonen, Mrs. Alexander  female  22.0    1.0
  • Related