0

Sorry, I'm stuck with on a basic task but I'm new to python so bear with me.

I'm trying to combine two values in a pandas dataframe into a separate column. I'm trying to combine the date values with the sport values. See code below:

date        sport       revenue
1/1/2019    baseball    100
1/2/2019    basketball  200

I want the final output to include the new column "date_sport_concat" w/concatenated values:

date        sport       revenue     date_sport_concat
1/1/2019    baseball    100         1/1/2019#baseball
1/2/2019    basketball  200         1/2/2019#basketball
nia4life
  • 333
  • 1
  • 5
  • 17

1 Answers1

2

Do:

df['date_sport_concat'] = df.date.astype(str) + "#" + df.sport
print(df)

Output

       date       sport  revenue    date_sport_concat
0  1/1/2019    baseball      100    1/1/2019#baseball
1  1/2/2019  basketball      200  1/2/2019#basketball
Dani Mesejo
  • 61,499
  • 6
  • 49
  • 76