0

I am extracting 2 columns from 2 different CSV with panda and I would like to print the 2 columns extracted.

I have no problems printing out each column separately, but when I want to print the 2 columns inline, it returns NaN values instead of float.

To be clearer, here's the code:

import pandas as pd

col_list = ["ID",]
df = pd.read_csv("waterproofposters.csv", usecols=col_list)

col_list = ["Regular price",]
dg = pd.read_csv("tempwaterproofposters.csv", usecols=col_list,)

dh = pd.DataFrame((df)|(dg))

print (df)
Output: 
          ID
     0    23770.0
     1    23771.0
     2    23772.0
     3    23773.0
     4    23774.0

print (dg)
Output: 
        Regular price
     0          25.79
     1          40.19
     2          55.19
     3          69.59

print (dh)
Output:
          ID  Regular price
     0   NaN            NaN
     1   NaN            NaN
     2   NaN            NaN
     3   NaN            NaN
     4   NaN            NaN

Wanted output:

     ID          Regular price
0    23770.0      25.79
1    23771.0      40.19
2    23772.0      55.19
3    23773.0      69.59
4    23774.0      NaN or null
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
Aissa Laribi
  • 97
  • 1
  • 1
  • 8
  • Are you trying to merge two dataframes, or two series into a dataframe ? Would this answer help : https://stackoverflow.com/questions/18062135/combining-two-series-into-a-dataframe-in-pandas ? – GuitarExtended Jun 20 '21 at 16:08
  • @GuitarExtended The quoted link is for combining 2 series. Here is 2 dataframes. – SeaBean Jun 20 '21 at 18:01

1 Answers1

2

You can use .join() to join the 2 dataframes vertically, instead of dh = pd.DataFrame((df)|(dg))

dh = df.join(dg)

Result:

print(dh)

        ID  Regular price
0  23770.0          25.79
1  23771.0          40.19
2  23772.0          55.19
3  23773.0          69.59
4  23774.0            NaN

SeaBean
  • 22,547
  • 3
  • 13
  • 25