New to Python and Pandas, all insights appreciated on this.
I'm working on a script that takes two csvs and combines them. However, the final output fails to write some rows, or those rows get overwritten - it's unclear to me what's happening.
The first csv, posts.csv
is structured like this, with 21 rows (with a header row):
user_id, text
6354, text1
5457, text2
5109, text3
The second csv, replies.csv
is similarly structured, with 38 rows (including header). The user_id
field in the first and second csv's refers to the same users:
user_id, text
5457, texta
5109, textb
5350, textc
Here's my code for combining the two csv's:
df = pd.concat(
map(pd.read_csv, ['posts.csv', 'replies.csv']), ignore_index=True)
df.to_csv("Control2.csv", index=False)
My output file, Control2.csv
, should contain 58 rows (57 rows + 1 header row). However, only 43 rows are written. It appears there are missing rows from both csv's. Any idea what may be happening here? All assistance appreciated.