'Combine Two Data Set CSV Files in Python
I have 2 datasets and each has 2 columns namely code, description. I want to read both the files search for similar text and map the codes of dataset 1 and dataset 2 together. For example.
file1.csv
code, description
111, Milk producer
112, IT specialist
file2.csv
code, description
001, Milkman
002, Driver
Now the combined dataset would be, file_combined.csv
code1, description1, code2, description2
111,milk producer,001,milk man
112,IT specialist,002,drvier
Solution 1:[1]
import pandas as pd
d1 = pd.read_csv('path/to/file1.csv')
d2 = pd.read_csv('path/to/file2.csv')
d1.rename(columns={'code':'code1', 'description': 'description1'}, inplace=True)
d2.rename(columns={'code':'code2', 'description': 'description2'}, inplace=True)
new_df = pd.concat([d1, d2], axis=1)
new_df.to_csv('path/to/new_file.csv', index=False)
This does not solve the part of search for similar text and map the codes of dataset 1 and dataset 2 together . Please clarify more and we can solve it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MSS |
