Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

More Books

Students also viewed these Databases questions

Question

2. Define identity.

Answered: 1 week ago

Question

1. Identify three communication approaches to identity.

Answered: 1 week ago

Question

4. Describe phases of majority identity development.

Answered: 1 week ago