Skip to content

Instantly share code, notes, and snippets.

@Ray901
Created July 27, 2015 10:30
Show Gist options
  • Save Ray901/b654ef8fc2c2e259603b to your computer and use it in GitHub Desktop.
Save Ray901/b654ef8fc2c2e259603b to your computer and use it in GitHub Desktop.
use python to create dataFrame
import numpy as np
import pandas as pd
import string , random
def randomword(length):
return ''.join(random.choice(string.uppercase[0:5]) for i in range(length))
df1 = pd.DataFrame(list(randomword(50)),columns=['user'])
df2 = pd.DataFrame(np.random.randint(100, size=(50,2)),columns=['G1','G2'])
DF = pd.concat([df1,df2],axis=1)
print DF.groupby('user').agg([np.sum,np.mean])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment