Python Forum
Extract data csv file and write in another file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extract data csv file and write in another file
#1
I have to write a Python application to read a CSV input file (appsUsage.csv) and generate an output file counting the frequency of the apps usage per user. The first column of the input file contains user id (user_id) and the second column contains the name of the app (app_name). From appsUsage.csv, I have to count the frequency of apps usage on individual user basis to generate app_Rank, and transform to a new data set named appsIndividualUsage.csv with the following columns: user_id; app_name; app_Rank.
For example if appsUsage.csv has following events
a facebook a facebook a linkedin b google b yahoo b yahoo
Then appsIndividualUsage.csv would be:
a facebook 2; a linkedin 1; b google 1; b yahoo 2;
Here is my code that I am struggling with :
>>>import csv with open(‘C:\\Users\\anne\\Desktop\\appsUsage.csv’, mode='r') as f_in, open(‘C:\\Users\\anne\\Desktop\\appsIndividualUsage.csv’, mode='w', newline='') as f_out: 
f_reader = csv.reader(f_in, dialect=csv.excel_tab) 
f_writer = csv.writer(f_out, dialect=csv.excel_tab) 
for line in reader: 
if line is equal then write it in writer and add a row of frequency
i totally don't know how to write the last line of my code Confused


If someone can help  Smile


Thank you
Reply


Messages In This Thread
Extract data csv file and write in another file - by alexgrand - Nov-11-2016, 02:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation URGENT: How to plot data from text file. Trying to recreate plots from MATLAB JamieAl 4 3,557 Dec-03-2023, 06:56 AM
Last Post: Pedroski55
  Newbie here. Create an array from file data? Rayj00 2 1,244 Jan-13-2023, 01:35 PM
Last Post: perfringo
  about write file wrong (Edit directly online) CNenfan 4 2,526 Jan-29-2021, 05:32 AM
Last Post: deanhystad
  Write to file emilng 1 1,723 Nov-08-2020, 08:44 PM
Last Post: Gribouillis
  Can we store value in file if we open file in read mode? prasanthbab1234 3 2,575 Sep-26-2020, 12:10 PM
Last Post: ibreeden
  Changing the content of the table and saving the new data into another file femke_pythonquestion123 1 1,577 Sep-18-2020, 12:06 PM
Last Post: femke_pythonquestion123
  Read data from a CSV file in S3 bucket and store it in a dictionary in python Rupini 3 6,999 May-15-2020, 04:57 PM
Last Post: snippsat
  Read text file, process data and print specific output Happythankyoumoreplease 3 2,921 Feb-20-2020, 12:19 PM
Last Post: jefsummers
  Data extraction from (multiple) MS Word file(s) in python Den0st 8 7,925 Sep-19-2019, 10:07 PM
Last Post: Den0st
  help! function that checks if a file is a bed file, tips so i can code it myself lilyS 1 2,380 May-31-2019, 12:41 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020