If the name is the same as Python csv phone number, add the member number and shipping number

Asked 2 years ago, Updated 2 years ago, 70 views

If the phone number and name are the same, I would like to put the shipping number at the back of the member number and send it to a new csv file.

Please give me some tips on what to do.

python csv list dictionary

2022-09-20 14:31

1 Answers

You can use pd.merge.

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.merge.html

>>> import pandas as pd


>> a = pd.DataFrame ({"Name": ["Younghee", "Minsu"], "Phone Number": ["424", "114"], "Member Number": ["110", "104"]})
>> b = pd.DataFrame ({"Name":["Younghee", "Minsu"], "Phone Number":["424", "114"], "Shipping Number":["12341", "12355"]})
>>> a
   Name Phone Number Member Number
0 Younghee 424 110
1 Minsu 114104
>>> b
   Name Phone Number Shipping Number
0 Younghee 424 12341
1 Minsu 114 12355
>>> c = pd.merge(a,b,on=["Name", "Phone Number"])
>>> c
   Name Phone Number Member Number Delivery Number
0 Younghee 424 110 12341
1 Minsu 114 104 12355
>>> print(c.to_markdown())
|    | Name | Phone number | Member number | Shipping number |
|---:|:-------|-----------:|-----------:|-----------:|
|  0 | Younghee | 424 | 110 | 12341 |
|  1 | Minsu | 114 | 104 | 12355 |


2022-09-20 14:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.