Git Product home page Git Product logo

code-snippets's People

Contributors

shadrock avatar

Watchers

 avatar  avatar

code-snippets's Issues

Defining a function to extract information from multiple files based on a key word

What am I trying to do?

I'm trying to create a function that will traverse multiple tables stored in .csv files; find a given word; extract the values for that word in the table (e.g. that word's entire record) along with the headers for the values; and concatenate them all in a new .csv.

Example Input & Output

I have 3 .csv files that contain information for three different cities: Mumbai, Nairobi, and Jakarta. I want to extract all of the information regarding Nairobi and concatenate it in a separate file. Each, separate, .csv contains the following:

csv1

City GDP per capita
Mumbai 123
Nairobi 321
Jakarta 231

csv2

City Population Pop male Pop female
Mumbai 1,000 500 500
Nairobi 3,000 1,500 1,500
Jakarta 2,000 1,000 1,000

csv3

City ISP per capita
Mumbai 12
Nairobi 32
Jakarta 23

I want the function to result in the following output:

City GDP per capita Population Pop male Pop female ISP per capita
Nairobi 321 3,000 1,500 1,500 32

Dependency issue with Python packages / modules.

Background

I am running Python 3.7.1 on a Mac. Most of the time I write scripts in Atom and run them in terminal. However, for a lot of my course preparation and tinkering around I use Anaconda / Jupyter Notebooks. I'm using v 1.9.6.

I am currently working on a web scraping script that involves importing the requests library. When I test the first part of the script I get an error message that suggests a dependency issue between two other Python libraries: urllib3 (v 1.24.1) or chardet (v 2.3.0).

Expected behavior

Import the library and run it.

Actual Behavior

Code and error message are as follows:

import requests

url = 'http://www.showmeboone.com/sheriff/JailResidents/JailResidents.asp'
response = requests.get(url)
html = response.content
print(html)

This results in the following error message:

/anaconda3/lib/python3.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.24.1) or chardet (2.3.0) doesn't match a supported version!
  RequestsDependencyWarning)

Questions

  • What is the best way to solve this? Is it possible that I have multiple installs of Python (or of libraries) in different places that are in conflict or is this a case of simply needed to update something to the most recent version (or even go back to an older version)?
  • Is it possible that I shouldn't be using the import library at all?

Online resources

StackOverflow post that seems related.

File renaming script starting at #2 and not 0 or #1

I've written the Python script found here, to rename files in a given directory. The output should be all files in a folder renamed as follows: IDCE_1, IDCE_2, etc. The script works well with the exception that it starts naming with IDCE_2, and not IDCE_1. Any idea what I'm doing wrong? @willdoran (no idea if tagging you in my private repo will actually do anything at all. But look how official this issue is!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.