Search Results
|
Post |
Author |
Forum |
Replies |
Views |
Posted
[asc]
|
|
|
Thread: Python pandas dataframe simulate football points system.
Post: Python pandas dataframe simulate football points s...
Hello:
import pandas as pd
import numpy as np
dfGames = pd.DataFrame.from_items([('TeamsHome', ['A', 'B', 'C']), ('TeamsAway', ['B', 'C', 'A']),('Games', [1, 1, 1]), ('HomeGoals', [2, 0, 1]), ('AwayG... |
|
zydjohn |
Data Science |
0 |
2,217 |
Mar-11-2018, 11:42 PM |
|
|
Thread: Python show the combinations of list of elements
Post: RE: Python show the combinations of list of elemen...
Hello:
I have figured out the following:
def combines(items, picks, len_unit):
combined = []
for ndx, item in enumerate(items):
current = items[ndx]
remains = [n for n in items... |
|
zydjohn |
General Coding Help |
6 |
7,503 |
Mar-06-2018, 11:23 PM |
|
|
Thread: Python show the combinations of list of elements
Post: RE: Python show the combinations of list of elemen...
Hello:
Thank you very much, your code works for C4_2:
C4_2 = [ 'ABCD', 'ABEF', 'ABGH', 'CDEF', 'CDGH', 'EFGH' ]But in my original post, I need other 2 combination results:
C4_3 = [ 'ABCDEF', 'ABCDGH',... |
|
zydjohn |
General Coding Help |
6 |
7,503 |
Mar-06-2018, 09:01 PM |
|
|
Thread: Python show the combinations of list of elements
Post: Python show the combinations of list of elements
letters = [ 'AB', 'CD', 'EF', 'GH']I have a list of 4 elements with 2-letter each element, I want to find the combinations for the following:
C4_2 = [ 'ABCD', 'ABEF', 'ABGH', 'CDEF', 'CDGH', 'EFGH' ]
... |
|
zydjohn |
General Coding Help |
6 |
7,503 |
Mar-06-2018, 06:43 PM |
|
|
Thread: Python find the minimum length of string to differentiate dictionary items
Post: RE: Python find the minimum length of string to di...
Hello:
I don't quite understand your meaning.
Please show me your code if you know how to do this.
As I am rather new for python programming, I can't figure this out by myself now.
Thanks, |
|
zydjohn |
General Coding Help |
3 |
3,628 |
Mar-03-2018, 12:44 PM |
|
|
Thread: Python find the minimum length of string to differentiate dictionary items
Post: Python find the minimum length of string to differ...
dTeamNames = {'A': 'Man City', 'B': 'Man United', 'C': 'West Brom', 'D': 'West Ham' }Hello:
I have a dictionary contains a key and a team name as the example above.
Now, I want to find a way to create... |
|
zydjohn |
General Coding Help |
3 |
3,628 |
Mar-03-2018, 11:06 AM |
|
|
Thread: Newbie question to use lambda on multiple columns of a dataframe
Post: Newbie question to use lambda on multiple columns ...
data={'id': [0,1,2,3], 'A':[1.1, 1.2, 1.3, 1.4], 'B':[1.0, 1.1, 1.2, 1.3], 'C':[1.1, 1.1, 1.3, 1.3], 'D':[10.0, 20.0, 30.0, 40.0]}
df0=pd.DataFrame(data)
df1=df0.set_index('id')
def get_sum(df):
... |
|
zydjohn |
General Coding Help |
0 |
5,816 |
Jan-23-2018, 06:08 PM |
|
|
Thread: Newbie question to return only the index of a dataframe
Post: Newbie question to return only the index of a data...
import datetime
import numpy as np
import pandas as pd
def get_index(df, offset):
print(df.iloc[offset:df.index.max(), 0:0])
return (df.iloc[offset:df.index.max(), 0:0])
data={'id': [0,1,2,3... |
|
zydjohn |
Data Science |
0 |
2,571 |
Jan-22-2018, 03:40 PM |
|
|
Thread: Question for dataframe to replace INF value
Post: Question for dataframe to replace INF value
import pandas as pd
df1 = pd.DataFrame({'a': [1.0, 1.1, 1.2 ], 'b': [ 0.5, 1.1, 1.0 ]})
mid = (df1['a'] + df1['b']) / 2.0
aMid = df1['a'].sub(mid)
bMid = df1['b'].sub(mid)
aWid = (a1 / aMid)
bWid = (a... |
|
zydjohn |
Data Science |
0 |
5,158 |
Jan-15-2018, 10:00 PM |
|
|
Thread: Newbie question to add columns in dataframe
Post: Newbie question to add columns in dataframe
Hello:
I have a CSV file (C:\Temp\NameList.CSV), it has exactly 20,000 records, like this:
First Name, Last Name (Field names)
John, Doe
......
Xyz, Fini
I want to read the CSV and convert it to data... |
|
zydjohn |
General Coding Help |
1 |
2,658 |
Dec-23-2017, 08:30 PM |
|
|
Thread: Newbie question to show nested namedtuple list
Post: RE: Newbie question to show nested namedtuple list
(Dec-18-2017, 10:53 PM)mpd Wrote: A dict would probably be more appropriate in the case. You could map salesperson to sales. But perhaps that violates a constant... Is this an assignment?Hello,
As ... |
|
zydjohn |
General Coding Help |
4 |
4,901 |
Dec-18-2017, 11:04 PM |
|
|
Thread: Newbie question to show nested namedtuple list
Post: Newbie question to show nested namedtuple list
Hello:
I have some code, which is not finished yet:
import collections
Sales = collections.namedtuple('Sales', ['ID', 'QuarterNo', 'QuarterSales', 'TotalSales'])
Q1Sales = collections.namedtuple('Q1S... |
|
zydjohn |
General Coding Help |
4 |
4,901 |
Dec-18-2017, 09:45 PM |
|
|
Thread: Newbie question for a kind of rolling average of list of lits
Post: Newbie question for a kind of rolling average of l...
Hello:
I have one list of lists, like this:
totals = [[1, 2, 3], [2, 3, 4], [5, 6, 7], [10, 9, 8], [4, 5, 6]]I need a function to get a kind of rolling average.
The rule is: for every 2 elements in th... |
|
zydjohn |
General Coding Help |
3 |
3,334 |
Dec-16-2017, 09:13 PM |
|
|
Thread: How many money in 30 days.
Post: RE: How many money in 30 days.
import math
def money_days(start, days):
power2days = math.pow(2, days)
amount = start * power2days
print(amount)
money_days(0.01, 30)
'''
The result is: 10737418.24
So, with the startin... |
|
zydjohn |
General Coding Help |
4 |
5,753 |
Dec-16-2017, 11:51 AM |
|
|
Thread: Newbie question for complicated namedtuple generation
Post: Newbie question for complicated namedtuple generat...
Hello:
I have some code by hand:
import collections
listA = [ 1.1, 1.2, 1.3, 1.4, 1.2, 1.1, 1.0, 1.1, 1.2, 1.3 ]
listB = [-1.0,-1.1,-1.2,-1.3,-1.1,-1.0,-0.9,-1.0,-1.1,-1.2 ]
listC = [ 0.0, 1.0, 1.2, 1... |
|
zydjohn |
General Coding Help |
0 |
2,172 |
Dec-16-2017, 09:50 AM |
|
|
Thread: Newbie question for unzip zipped list
Post: Newbie question for unzip zipped list
Hello:
I have some code, but I want to do the reverse:
list1 = [1,2,3,4]
list2 = [2,3,4,5]
list3 = [3,4,5,6]
list4 = [4,5,6,7]
zip4List = zip(list1,list2,list3,list4)The fact is: I already have a zipp... |
|
zydjohn |
General Coding Help |
2 |
2,716 |
Dec-15-2017, 08:34 PM |
|
|
Thread: Newbie question for bulk insert into SQL Server database
Post: RE: Newbie question for bulk insert into SQL Serve...
Hello:
Thanks for help, I read the document at:
http://www.pymssql.org/en/stable/pymssql...compliance
But I can't find useful bulk insert code.
Please advise or write some code to bulk insert the reco... |
|
zydjohn |
General Coding Help |
6 |
12,423 |
Dec-14-2017, 04:47 PM |
|
|
Thread: Newbie question how to find the coefficient for each variable
Post: RE: Newbie question how to find the coefficient fo...
model.params is the correct answer.
Thanks, |
|
zydjohn |
Data Science |
10 |
12,193 |
Dec-14-2017, 04:43 PM |
|
|
Thread: Newbie question how to find the coefficient for each variable
Post: RE: Newbie question how to find the coefficient fo...
Hello,
Thanks for your help, however, after I read the web page listed, still there is no example how to get results I want.
I even found the source code for: Source code for statsmodels.regression.li... |
|
zydjohn |
Data Science |
10 |
12,193 |
Dec-13-2017, 08:51 PM |
|
|
Thread: Newbie question how to find the coefficient for each variable
Post: Newbie question how to find the coefficient for ea...
Hello:
I had some code to do multiple variable linear regression using statsmodels, the following is my code:
import numpy as np
import statsmodels.api as sm
import statsmodels.formula.api as smf
impo... |
|
zydjohn |
Data Science |
10 |
12,193 |
Dec-13-2017, 05:25 PM |