Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Make a table from a json output
#11
(Jan-01-2019, 09:42 PM)snippsat Wrote: ...

Thx for input. Im using pycharm. From what i understand VS code is just another editor

Im still in doubt how i add columns and how to sum up 2 columns to the new one.

/ Carsten
Quote
#12
(Jan-04-2019, 08:58 PM)carstenlp Wrote: Thx for input. Im using pycharm. From what i understand VS code is just another editor
Sure,but in my option the best multilanguage editor out there and take how Python work in editor more seriously than others.

(Jan-04-2019, 08:58 PM)carstenlp Wrote: Im still in doubt how i add columns and how to sum up 2 columns to the new one.
Like this.
import pandas as pd
pd.set_option('display.max_columns', None)

d = {
    'date': [20110911, 20110918],
    'day': ['Sunday', 'Sunday'],
    'line': [2.0, 6.0],
    'o:points': [12, 30],
    'o:team': ['Falcons', 'Saints'],
    'points': [30, 13],
    'season': [2011, 2011],
    'site': ['home', 'away'],
    'team': ['Bears', 'Bears'],
    'total': [40.5, 47.0],
    'week': [1, 2]
}

df = pd.DataFrame.from_dict(d)
df['total_points'] = df['o:points'] + df['points']  # assigned to a new column
print(df)
Will add a new column.
Output:
week total_points 0 1 42 1 2 43
Sum it all up:
df['total_points'].sum()
85
carstenlp likes this post
Quote
#13
(Jan-04-2019, 10:37 PM)snippsat Wrote: ...

Thanks snippsat. Dance
Quote
#14
Hi

I got the added column now, that returns true/false wether the points is larger than o:points.
I have then added to it change the true/false to 1/0 so i get a integer back.

If points == o:points i want it to return 0.5 instead. How do i do that ?

I have added just part for the code. Hope its enough for it to make sense.
I have added the 2nd line (df['SUresult'] = df['points'] == df['o:points'])
That returns the true if points=o:points and the match is a draw. How can i change that true to 0.5 and how do i set up if so it will continue if its not a draw game.

df = pd.DataFrame.from_dict(d)
    df['SUresult'] = df['points'] == df['o:points']
    df['SUresult'] = df['points'] > df['o:points'] # Add Straight Up results Column and see if team Won SU
    df['SUresult'] = df['SUresult'].astype(int) # Change the Dataframe boolan to interger 0 or 1
Thanks

/ Carsten
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Problem Table Output Phil 4 138 May-19-2019, 12:17 PM
Last Post: Phil
  Transposing Table salihozturk 3 229 Mar-03-2019, 06:55 PM
Last Post: salihozturk
  CiscoConfParse to json output anna 6 361 Feb-12-2019, 10:40 AM
Last Post: anna
  Python - create JSON output dragan979 1 268 Dec-28-2018, 12:20 PM
Last Post: dragan979
  times table aocii 3 436 Dec-26-2018, 01:30 PM
Last Post: metulburr
  make a frequency table davidm 6 358 Dec-23-2018, 12:02 PM
Last Post: davidm
  How to pivote table SriRajesh 1 344 Dec-06-2018, 07:14 AM
Last Post: scidam
  Unexpected output when searching for a string from os.popen output FujiJean 3 500 Oct-02-2018, 11:39 AM
Last Post: volcano63
  json.load() is making json file into string and not python disctionary Heisenberg 2 692 Jun-10-2018, 08:29 AM
Last Post: Larz60+
  Unable to parse JSON output dragan979 1 685 Apr-20-2018, 02:24 PM
Last Post: dragan979

Forum Jump:


Users browsing this thread: 1 Guest(s)