Python Programming & other inferior programming languages thread

Discussion in 'The Mainboard' started by Walt Disney, Jul 15, 2015.

  1. nofatchildren - cissp

    nofatchildren - cissp Free Da Guys
    Donor TMB OG
    Tiger Woods

    For the quick data analysis type stuff you are trying to do, R is probably the most efficient language. It's optimized for this type of stuff. In fact, Pandas was built in Python simply to make it easier to use Python like R.

    Just do Text-to-Columns on your City column in Excel using the comma as a delimiter and then save your file as a CSV (e.g "test.csv" in the below code)

    Then, something like this (and I'm by no means an expert in R) is pretty quick:

    Code:
    #install packages used for easier reshaping and sorting of data
    install.packages("reshape2")
    install.packages("plyr")
    
    #load libraries
    library(reshape2)
    library(plyr)
    
    #read in your data
    data <- read.csv("test.csv", header = TRUE, strip.white=TRUE)
    
    #use melt function to take wide-format data and "melt" it to long format using the State as the ID and name the new output column "City"
    dat2b <- melt(data, id.vars=("State"),
        value.name = "City")
    
    #create new data frame with the columns you want and sort them alphabetically, first by state then by city
    newdata <- arrange(dat2b[, c(1,3)], State, City)
    
    #print new data frame
    newdata
    
    So, without all the fluff, you are looking at like three lines of actual code
    Code:
    data <- read.csv("test.csv", header = TRUE, strip.white=TRUE)
    dat2b <- melt(data, id.vars=("State"), value.name = "City")
    newdata <- arrange(dat2b[, c(1,3)], State, City)
    
     
    Name P. Redacted and Walt Disney like this.
  2. Walt Disney

    Walt Disney #Dawgzy
    Donor TMB OG
    Georgia BulldogsManchester City


    awesome - gonna try this

    still need to figure out this in Python. Our team currently has a Python vs R rivalry going so team Python is trying to do everything in Python.

    Gonna try the split string thing posted last page also tomorrow
     
  3. Walt Disney

    Walt Disney #Dawgzy
    Donor TMB OG
    Georgia BulldogsManchester City

    awesome that's cool that you can attach code in here like that

    Code:
    import tweepy
    from tweepy import OAuthHandler
    from tweepy import Stream
    from tweepy.streaming import StreamListener
    
    
    
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_secret)
    
    api = tweepy.API(auth)
    
    
    class MyListener(StreamListener):
    
        def on_data(self, data):
            try:
                with open('/pythontwitter.txt', 'a') as f:
                    f.write(data)
                    return True
            except BaseException as e:
                print("error on_data: %s" % str(e))
            return True
    
        def on_error(self, status):
            print(status)
            return True
    
    twitter_stream = Stream(auth, MyListener())
    twitter_stream.filter(track=['#MCFC','LFC','Liverpool', 'MCFC', '#Liverpool', 'Manchester City'])
    
     
    Shiggityshwo likes this.
  4. nofatchildren - cissp

    nofatchildren - cissp Free Da Guys
    Donor TMB OG
    Tiger Woods

    Btw, by habit I typically use Excel "Text-to-Columns" to split one column into multiple columns before I even import the data (like above). It's super quick, and with only one column to split, it's not a big deal. But let's say that you had a shit load of columns that were this way (so that manually splitting them all in Excel would be tedious) or didn't have access to Excel...

    You can do it really easily in R as well. Just requires one extra package to install, and then the above code would look like:

    Code:
    install.packages("reshape2")
    install.packages("plyr")
    install.packages("data.table")
    
    library(reshape2)
    library(plyr)
    library(data.table)
    
    data <- fread("test.csv", sep=",", sep2 = ",", header=TRUE)
    dat2b <- melt(data, id.vars=("State"), value.name = "City")
    newdata <- arrange(dat2b[, c(1,3)], State, City)
    newdata
    
     
    #104 nofatchildren - cissp, Jul 20, 2015
    Last edited: Jul 20, 2015
    Walt Disney likes this.
  5. Walt Disney

    Walt Disney #Dawgzy
    Donor TMB OG
    Georgia BulldogsManchester City

    nofatchix likes this.
  6. Walt Disney

    Walt Disney #Dawgzy
    Donor TMB OG
    Georgia BulldogsManchester City

    looks like this can be used for a stackoverflow

    pretty impressed with the amount of people we have ITT :chatzy:
     
    Where Eagles Dare likes this.
  7. fsck~

    fsck~ ~
    Staff TMB OG

    Huh, haven't looked at it yet but that could be really useful. I'm currently setting up a python fantasy football AI league, like computer chess kind of. Have everything set up to simulate leagues and I'm trying to get a write up done to let people start coding their AIs tomorrowish. It's just drafting this season so I pass available players and their adp, projection, and past stats to each AI to draft.

    Which by the way, anyone interested in joining? No pressure to be good, this season is more just an experiment. I can help with python too if people are interested in learning more. If anyone is I can post more details.
     
  8. fsck~

    fsck~ ~
    Staff TMB OG

    Yep, I'm basically all java and mobile.
     
    Barves2125 likes this.
  9. Pile Driving Miss Daisy

    Pile Driving Miss Daisy It angries up the blood
    Donor
    Texas LonghornsAtlanta BravesAtlanta HawksAtlanta FalconsAtlanta UnitedGeorgia Southern Eagles

    Using Java to write mobile apps? How hard was that to start learning?
     
  10. broXcore

    broXcore cat
    Donor
    Kansas State WildcatsNew York KnicksKansas City ChiefsSporting Kansas CityTottenham HotspurFormula 1

    i use sql and vb a lot for my job, but i'd love to get java down, since most of our software is being migrated to java based applications. any advice? not sure if i should just jump straight into java or start with another language. it'd be self taught, so any resources would be great.
     
  11. Where Eagles Dare

    Where Eagles Dare The Specialist Show On Earth
    Donor
    Auburn TigersAtlanta BravesWashington Football TeamAtlanta United

  12. fsck~

    fsck~ ~
    Staff TMB OG

    If you already know java it's easy. It's also deceiving because (especially with your first app) writing the app if half or less of the work. You'll then have to adjust it to work on so many different screens.
     
  13. Barves2125

    Barves2125 "Ready to drive the Ferarri" - Reuben Foster
    Donor TMB OG
    Alabama Crimson TideAtlanta BravesManchester CityBirmingham LegionUnited States Men's National Soccer TeamPoker

    Are you freelance or do you work for a firm or what?
     
  14. J.R. Bob Dobbs

    J.R. Bob Dobbs Fan of: Firing Coaches, Cutting Players

  15. oac001

    oac001 Chompzy Chairman
    Staff Donor TMB OG
    Florida GatorsSeattle MarinersDenver NuggetsDenver BroncosUnited States Men's National Soccer Team

    native android app development is mainly Java but not many people do native anymore. i'd go with c# (unity, xamarin, etc.) for mobile apps.
     
  16. fsck~

    fsck~ ~
    Staff TMB OG

    Big company, just don't post it to stay slightly disconnected from anything said here.
     
    Barves2125 likes this.
  17. Barves2125

    Barves2125 "Ready to drive the Ferarri" - Reuben Foster
    Donor TMB OG
    Alabama Crimson TideAtlanta BravesManchester CityBirmingham LegionUnited States Men's National Soccer TeamPoker

    Understandable. Can you tell me this though? About what price range and time range could someone expect to have Version1 built for an app? And do you think it's smarter to build for Android and then copy/mirrow for an iOS build or vice versa or simultaneous builds?
     
  18. fsck~

    fsck~ ~
    Staff TMB OG

    Too variable to tell you without knowing what's in the app. And I don't do IOS or make any apps for sales so don't have much advice there either. If you are going paid app though ios might be better first, while free app might be reverse.
     
    Barves2125 likes this.
  19. Joe_Pesci

    Joe_Pesci lying dog-faced pony soldier
    Donor
    Wolfsburg

    i want to make a weed delivery app because it becomes legal to sell in oregon on october 1st but i don't have the skills to make it, the money to pay someone to do it, or the experience to set up a delivery business
     
  20. Pile Driving Miss Daisy

    Pile Driving Miss Daisy It angries up the blood
    Donor
    Texas LonghornsAtlanta BravesAtlanta HawksAtlanta FalconsAtlanta UnitedGeorgia Southern Eagles

    I mentioned functional programming earlier and heard that Swift is the shit for iOS stuff, but I've been writing a lot in Java lately and this would be a fun project (work in C# though). Also I'm still new to the development world and have too many interests. Best to probably sharpen my skills in a particular area for marketability before doing every fun thing I can think of.
     
  21. kennypowers

    kennypowers Big shit like a dinosaur did it
    Donor TMB OG
    UCF KnightsAtlanta BravesJacksonville Jaguars

    matplotlib is the shit by the way. I mostly use gnuplot to make plots but I have been transitioning to matplotlib/python. You can make excel charts just look like straight up shit when you can master either of these two tools. Gnuplot is extremely handy if you need to plot millions of records or to do basic manipulation on columns. I honestly try to use excel as little as possible,I mostly have it open as a calculator or a unit converter.
     
  22. Name P. Redacted

    Name P. Redacted I have no money and I'm also gay
    Donor
    Kansas State WildcatsSeattle Kraken

    ive barely touched the surface on swift, but it's very similar to python syntax-wise.
     
  23. broXcore

    broXcore cat
    Donor
    Kansas State WildcatsNew York KnicksKansas City ChiefsSporting Kansas CityTottenham HotspurFormula 1

    seems relatively simple. also, there's an iOS app called "swifty" that's a daily lesson kind of teaching app for swift. seems like a good starter.
     
    Name P. Redacted likes this.
  24. Walt Disney

    Walt Disney #Dawgzy
    Donor TMB OG
    Georgia BulldogsManchester City

    any help plz? Is this a good question for stackoverflow? I feel like they will be mean to me asking this.

    Loops with lists may not even be the best title idk. I only had 4 hours of sleep last night so I cannot think anymore today.

    http://stackoverflow.com/questions/31527116/python-loop-with-lists

    I feel dumb asking questions :/
     
  25. leroi

    leroi -
    Donor
    South Carolina GamecocksGrateful Dead


    i'm also working on a 'python fantasy football league.' it is a long-term project.

    i basically am building an entire world, i.e. like an ncaa dynasty sort of game, with fake players, but have not started working on the game engine yet
     
    #125 leroi, Jul 20, 2015
    Last edited: Jul 20, 2015
  26. leroi

    leroi -
    Donor
    South Carolina GamecocksGrateful Dead

    IMO just as a first step:

    in main, you probably want to check to see if the meeting is full / has been set yet for the given dates. If you have the green light, then run:

    def organize_meetings()

    which will contain the logic for randomizing all that shit, probably with for and while loops, which will repeatedly call

    def send_meeting_request()

    every time it populates/sends an individual meeting. Then go to sleep and in the morning figure out the logic behind organize_meetings.
     
    #126 leroi, Jul 20, 2015
    Last edited: Jul 20, 2015
  27. BellottiBold

    Donor
    Oregon Ducks

    I think people are generally helpful and not dickish when they understand what you are after. In this case you might explain that the current code can be used to email the single recipient with a single location in mind (even if it seems obvious to you) and then flesh out this end goal of random distribution. What does that really mean? Given that you have a list of 8 recipients and 4 locations is the idea to have 2 of them assigned to one of the 4 possible locations all day starting @ 8 during the range specified? It's a little unclear imo
     
    Walt Disney and leroi like this.
  28. BellottiBold

    Donor
    Oregon Ducks

    Been wondering how this is going ;)
     
  29. leroi

    leroi -
    Donor
    South Carolina GamecocksGrateful Dead

    its like building a model of the taj mahal out of toothpicks.

    i just built an algorithm that allows the AI to search by location. So the AI can calculate the distance between all ~3000 cities in the database, given the lat/lon coordinates of 2 points. That is going to help me with "Spring Scouting Camps", where recruits in the area show up and you can add them to your scouting list -- vs recruits that you seek out deliberately by scouting their high school ..... and how they respond to you based on distance/prestige/academics .... etc

    I actually have schools categorized. "State" "HBCU" "Mormon" "Baptist" "Private." Recruits have flags like "WillAttendMilitarySchool" and "PrefersCloseToHome." So it is what you'd call an incredibly "data rich environment." it is 51,000 lines of python code at this point.

    i'm still trying to develop the concepts, like how modeling of recruiting is supposed to work. How to scout, how to recruit, different actions that "Coaches" can take.
     
    #129 leroi, Jul 20, 2015
    Last edited: Jul 20, 2015
  30. Walt Disney

    Walt Disney #Dawgzy
    Donor TMB OG
    Georgia BulldogsManchester City

    F me I got another down arrow

    Yeah I suck at explaining things, will edit that
     
  31. Walt Disney

    Walt Disney #Dawgzy
    Donor TMB OG
    Georgia BulldogsManchester City

    fgt This isn't a code-writing or tutorial service; do some research and put a little effort into writing this yourself. – jonrsharpe1 min ago

    f my life,
     
  32. fsck~

    fsck~ ~
    Staff TMB OG

    Well then, you guys should join and make a drafting AI.
     
  33. fsck~

    fsck~ ~
    Staff TMB OG

    Just need to increase your google fu. Use stackoverflow when you have direct technical questions.
     
    Black Jesus and kennypowers like this.
  34. leroi

    leroi -
    Donor
    South Carolina GamecocksGrateful Dead

    i may

    my goal with this project is to make $$, though. is yours just for fun?
     
  35. kentucky_dawg

    kentucky_dawg Fan of: Georgia
    Donor
    Georgia Bulldogs

    Yeah, I've heard the difficult part of iOS is not the language itself but dealing with Apple's SDK.
     
    leroi likes this.
  36. leroi

    leroi -
    Donor
    South Carolina GamecocksGrateful Dead

    derp

    does that use the whole flex/flash/actionscript/flash builder sdk ?
     
  37. fsck~

    fsck~ ~
    Staff TMB OG

    Yeah, I don't have any monetization plans yet at least. It will all be open source for the first season.
     
  38. Walt Disney

    Walt Disney #Dawgzy
    Donor TMB OG
    Georgia BulldogsManchester City

    how old are yall?

    I'm pretty jealous how much yall know
     
  39. Walt Disney

    Walt Disney #Dawgzy
    Donor TMB OG
    Georgia BulldogsManchester City

    I'm only 3 months in though I guess so hopefully soon I'll be more of a beast pythoner
     
    Where Eagles Dare likes this.
  40. Pile Driving Miss Daisy

    Pile Driving Miss Daisy It angries up the blood
    Donor
    Texas LonghornsAtlanta BravesAtlanta HawksAtlanta FalconsAtlanta UnitedGeorgia Southern Eagles

    Walt you sound like me about a year ago. I'm still new and wanting to learn, but I was freaked out at how everyone seemingly knew so much more than I did and how in the hell could I learn enough to become a good programmer. Hopefully that feeling passes, but a big part is kind of learning how to learn. Stackoverflow can be a frustrating resource like you're finding out if you aren't crystal clear on your problem, but 95% of the time I need to figure out something at work I can usually find enough of an answer through google.
     
  41. BellottiBold

    Donor
    Oregon Ducks

    Plus that shit *never* goes away.

    You always don't know enough, even when you know what you are doing, if this is what you do professionally. Nature of the beast.
     
    leroi and fsck~ like this.
  42. kentucky_dawg

    kentucky_dawg Fan of: Georgia
    Donor
    Georgia Bulldogs

    I haven't really dug into it a whole lot to be honest, but I'm pretty sure iOS doesn't support Flash. Here are a list of the SDK contents:
    https://en.wikipedia.org/wiki/IOS_SDK#SDK_contents
     
  43. Pile Driving Miss Daisy

    Pile Driving Miss Daisy It angries up the blood
    Donor
    Texas LonghornsAtlanta BravesAtlanta HawksAtlanta FalconsAtlanta UnitedGeorgia Southern Eagles

    Very true. My boss is cool with me spending an hour or less a day doing coursework/non-work learning stuff so that makes me feel a little better. Just have to stay motivated to learn.
     
    Walt Disney likes this.
  44. kentucky_dawg

    kentucky_dawg Fan of: Georgia
    Donor
    Georgia Bulldogs

    This. The easy part is looking up the answers. Its when you know what questions to actually ask and look for that you start to really understand the concepts. That, and applying it to actual applications.

    The hard part, imo, is landing the job (once you're in you're golden if you have a basic grasp and can use resources like StackOverflow). I hate coding interviews, but I have bad anxiety so maybe it's just me.
     
  45. Walt Disney

    Walt Disney #Dawgzy
    Donor TMB OG
    Georgia BulldogsManchester City

    thats how it is with me/our team

    plus i'm really competitive and really hard on myself when i dont know something technically. I've been spending about 15 hours a week outside of work learning stuff
     
  46. kentucky_dawg

    kentucky_dawg Fan of: Georgia
    Donor
    Georgia Bulldogs

    This is my issue. I love learning but if I have nothing to apply it to it just doesn't stick. I think one of the best things you can do if you can't keep learning on the job is to start contributing to open source projects on github.
     
  47. broXcore

    broXcore cat
    Donor
    Kansas State WildcatsNew York KnicksKansas City ChiefsSporting Kansas CityTottenham HotspurFormula 1

    just going forward with the codeacadamy java lesson. figured that would be at least a start.
     
    Walt Disney likes this.
  48. Neyland

    Neyland Well-Known Member

    don't feel bad, first time I asked a question on stack overflow I got HAMMERED

    learned my lesson quickly
     
  49. Walt Disney

    Walt Disney #Dawgzy
    Donor TMB OG
    Georgia BulldogsManchester City


    reminding myself for tomorrow for this

    and to save this link https://blog.udemy.com/python-while-loop/
     
  50. kentucky_dawg

    kentucky_dawg Fan of: Georgia
    Donor
    Georgia Bulldogs

    Just a heads up, I don't think codeacademy offers courses on Java. JavaScript and Java are two different languages. JavaScript is a lot more front-end oriented.
     
    broXcore likes this.