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
0

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.