0

I have two dataframes df and df2 with contents as follows

dataframe df

enter image description here

dataframe df2

enter image description here

I'd like to add to df1 the two columns from df2 "NUMSESSIONS_ANDROID" and "AVGSESSDUR_ANDROID"

I do this as follows:

df['NUMSESSIONS_ANDROID'] = df2['NUMSESSIONS_ANDROID']
df['AVGSESSDUR_ANDROID']  = df2['AVGSESSDUR_ANDROID']

However when I print the resulting df I see ... in place of AVGSESSDUR_IOS (i.e. it appears to have swallowed that column)

Appreciate any help resolving this ....

enter image description here

CoolDocMan
  • 637
  • 7
  • 29
  • 3
    The `...` indicates that only part of the DataFrame is being shown in your terminal/output, so `'AVGSESSDUR_IOS'` is almost certainly still there it's just not shown. You can look at `print(df.iloc[:, 0:3])` to see the first 3 columns for instance. – ALollz Dec 27 '19 at 22:47
  • See `join, merge, concatenate` functions from pandas. [link]https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html – TZof Dec 27 '19 at 22:49
  • 1
    Thank you @ALollz. After your comment, I added the following two lines to increase the number of columns and width of console display and it worked! pd.set_option('display.max_columns',20) pd.set_option('display.width', 1000) – CoolDocMan Dec 27 '19 at 23:01

2 Answers2

2

As ALollz stated, the fact you are seeing ... in the output means there's "hidden" data that is part of the dataframe, but not showing in your console or IDE. However you can perform an easy print to check all the columns that your dataframe contains with:

  print(list(df))

And this will show you all the names of the columns in your df that way you can check whether the ones you want are there or not.

Furthermore you can print an specific column as a series (first line) or dataframe (second):

 print(df['column_name'])
 print(df[['column_name']])

If successful you will see the series/dataframe, if the column actually doesn't exist in your original dataframe, then you will get a KeyError.

Celius Stingher
  • 17,835
  • 6
  • 23
  • 53
2

Leveraging @ALollz's hint above ...

"The ... indicates that only part of the DataFrame is being shown in your terminal/output, so 'AVGSESSDUR_IOS' is almost certainly still there it's just not shown. You can look at print(df.iloc[:, 0:3]) to see the first 3 columns for instance."

I added the following two lines to increase the number of columns and width of console display and it worked:

pd.set_option('display.max_columns',20)
pd.set_option('display.width', 1000) 
print(df.iloc[:,0:5])
CoolDocMan
  • 637
  • 7
  • 29