January 2019
Beginner
318 pages
8h 23m
English
We are going to learn about how to merge data in Python. For that, we are going to use Python's pandas library. To merge the data, we are going to use two csv files that already created in the previous section, student1.csv and student2.csv.
Now, create a merge_data.py script and write the following code in it:
import pandas as pddf1 = pd.read_csv("student1.csv")df2 = pd.read_csv("student2.csv")result = pd.concat([df1, df2])print(result)
Run the script as follows:
$ python3 merge_data.pyOutput: Id Name Gender Age Address0 101 John Male 20 New York1 102 Mary Female 18 London2 103 Aditya Male 22 Mumbai3 104 Leo Male 22 Chicago4 105 Sam Male 21 Paris5 106 Tina Female 23 Sydney0 101 John Male 21 New York1 102 Mary Female 20 London ...
Read now
Unlock full access