Python icon indicating copy to clipboard operation
Python copied to clipboard

Python Code to get String and value from one file to another file.

Open bhrigwish opened this issue 2 years ago • 16 comments

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.

bhrigwish avatar Feb 07 '23 11:02 bhrigwish

What does this have to do with the repo?

tianyizheng02 avatar Feb 07 '23 14:02 tianyizheng02

Apologies, if any mistake. My first time here

bhrigwish avatar Feb 08 '23 05:02 bhrigwish

@bhrigwish Hey you working on this issue ?

ibrahim-string avatar Feb 09 '23 17:02 ibrahim-string

No. I am finding the solution. Do you got any?

bhrigwish avatar Feb 09 '23 17:02 bhrigwish

Yeah, I am working on that

ibrahim-string avatar Feb 09 '23 17:02 ibrahim-string

@bhrigwish you want the code for the problem or what ?

ibrahim-string avatar Feb 09 '23 18:02 ibrahim-string

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: @.***>

bhrigwish avatar Feb 09 '23 18:02 bhrigwish

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: @.***>

bhrigwish avatar Feb 13 '23 09:02 bhrigwish

Are you still working on this?

30adi avatar Feb 16 '23 04:02 30adi

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: @.***>

bhrigwish avatar Feb 16 '23 04:02 bhrigwish

Hey, still working on this? Maybe I can get a hand

svalls26 avatar Feb 26 '23 20:02 svalls26

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: @.***>

bhrigwish avatar Feb 27 '23 01:02 bhrigwish

Please provide me the 2 files, can you briefly describe how you want Data

Darsh0278 avatar Feb 27 '23 03:02 Darsh0278

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

30adi avatar Feb 27 '23 04:02 30adi

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 👍👍👍

Prashant-S29 avatar Mar 04 '23 05:03 Prashant-S29

hey , are you still working on it?

unicoDErn0 avatar Mar 04 '23 08:03 unicoDErn0

yaa actually i am working on this code

coolBrown12 avatar Apr 05 '23 12:04 coolBrown12

Seems as if problem has been solved

ChrisO345 avatar May 09 '23 22:05 ChrisO345