3

So i'm trying to predict the winner of a sport game, and i have 2 CSV files. One with the current year statistics and the other with last years statistics.

I would like to merge them but only with the colums from the first file:

So that if the first table has columns ['Away','Home','Result']

and the second one has ['Away','Home','Match-Rating']

the result would contain ['Away','Home','Result'] and the 'Result' column would contain 0 or other default value if not found in second CSV.

I tried :

data = panda.read_csv('PremierLeagueDataSet/19-20.csv')
display(data.head())
data2= panda.read_csv('PremierLeagueDataSet/18-19.csv')
data.append(data2)

but gives me a warning and doesn't do the wanted concatenation

FutureWarning: Sorting because non-concatenation axis is not aligned. A future version of pandas will change to not sort by default.

2
  • can you show the head of those df and the expected result Commented Jan 3, 2020 at 16:39
  • ['Div', 'Date', 'Time', 'HomeTeam', 'AwayTeam'] ==> 1st df ['Div', 'Date', 'HomeTeam', 'AwayTeam'] ==> 2nd df And i would like my result to be just like 1st df but for 'Time' to have a generic value Commented Jan 3, 2020 at 16:52

1 Answer 1

2

To block data2.Match-Rating from appending, invoke append passing data2 with column names to be included:

data.append(data2[['Away', 'Home']], ignore_index=True, sort=False)\
    .replace(np.nan, '')

As you can see, I added ignore_index=True to avoid repeating indices. I added also sort=False to avoid a warning concerning planned changes in future versions.

I added also replace to change NaN values into empty strings.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.