Question
Python for Data analyst. I'm parsing an excel document with thousands of entries. thus far, I've got code to change the excel to a csv,
Python for Data analyst.
I'm parsing an excel document with thousands of entries.
thus far, I've got code to change the excel to a csv, copy paste the entire document into a text file that is '|' explicitely serparted instead of coma separated.
Unfortunately, the data is missing information and I only want to copy and paste information from those that have a certain column entry that is a number ranging from 0 to 999.
Please help me write a code that will iterate/go through rows and search for a number ranging 0 to 999. If found, I want to go ahead and copy/paste that entry and 3 other columns in that row. If not found, please tell the code to skip to the next row instead of copying any information from columns of that row. This is to be copyied into a text file. my current code is below- ive replaced the directory with somewhere and something
import pandas as pd import os.path as op def extract_export_columns(df, list_of_columns, file_path): column_df = df[list_of_columns] column_df.to_csv(file_path, index=False, sep="|") #Orrginal file input_base_path = 'C:somewhere' main_df_data_file = pd.read_csv(op.join(input_base_path, 'somewhere ')) #Product of code output_base_path = r'C:somewhere' extract_export_columns(main_df_data_file, ['column1', 'column2', 'column3', 'etc'], op.join(output_base_path, 'something.txt')) extract_export_columns(main_df_data_file, ['column7'], op.join(output_base_path, 'some_other_thing.txt'))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started