Python
Python copied to clipboard
Python Code to get String and value from one file to another file.
Feature description
I am trying a Python Code to get a string and a value from one file to another. Below is the description:
File 1: Part Reference| Vehicle Applications XYZ1123 | Lodgy 12+, Captur 13+ ABC1147 | Golf 11+, Polo 14+
File 2: Car Model | Total Sales Lodgy | 1000 Captur | 400 Golf | 11000 Polo | 9000
I am looking for an output where in File 1 it appears next to Vehicle APplication the Car Model Names from File 2 and the sum of Car Model got.
I am working on Google COlab and got 2 files using pandas.
What does this have to do with the repo?
Apologies, if any mistake. My first time here
@bhrigwish Hey you working on this issue ?
No. I am finding the solution. Do you got any?
Yeah, I am working on that
@bhrigwish you want the code for the problem or what ?
Yes please
Sent from Yahoo Mail on Android
On Thu, 9 Feb 2023 at 23:47, @.***> wrote:
@bhrigwish you want the code for the problem or what ?
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
Good Morning Everyone, Just checking. Did anyone reached a solution or if anyone can guide me with pseudo code. Thanks and Regards,Bhrigwish Parekh
Sent from Yahoo Mail on Android
On Thu, 9 Feb 2023 at 23:47, @.***> wrote:
@bhrigwish you want the code for the problem or what ?
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
Are you still working on this?
Good Morning, Yes I am. But getting no where. If you have any solutions please share. Thanks and Regards,Bhrigwish Parekh
Sent from Yahoo Mail on Android
On Thu, 16 Feb 2023 at 9:45, Aditya @.***> wrote:
Are you still working on this?
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
Hey, still working on this? Maybe I can get a hand
Greetings, I am working but sure you can give it a try. Let me know if you have the solution. Regards
Sent from Yahoo Mail on Android
On Mon, 27 Feb 2023 at 1:47, @.***> wrote:
Hey, still working on this? Maybe I can get a hand
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
Please provide me the 2 files, can you briefly describe how you want Data
import csv
with open("file1.csv", "r") as f1: f1_reader = csv.reader(f1) f1_lines = list(f1_reader)
with open("file2.csv", "r") as f2: f2_reader = csv.reader(f2) f2_lines = list(f2_reader)
Create a dictionary to store car models and total sales from File 2
car_sales = {} for line in f2_lines[1:]: car_model, total_sales = line car_sales[car_model] = int(total_sales)
add car model names and total sales to each line based on the vehicle applications listed
res = [] for line in f1_lines[1:]: part_ref, vehicle_apps = line car_models = [] for car_model, total_sales in car_sales.items(): if car_model in vehicle_apps: car_models.append(car_model) total_sales_sum = sum([car_sales[car_model] for car_model in car_models]) output_line = [part_ref, vehicle_apps] + car_models + [str(total_sales_sum)] res.append(output_line)
with open("output.csv", "w", newline="") as outfile: writer = csv.writer(outfile) writer.writerow(["Part Reference", "Vehicle Applications"] + list(car_sales.keys()) + ["Total Sales"]) writer.writerows(res)
try this
i think i got it . well change the type of the file 1 and file 2 to CSV file. Then simply use panda module. Well I didn't remember the code exactly but it will work 👍👍👍
hey , are you still working on it?
yaa actually i am working on this code
Seems as if problem has been solved