-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Closed
Description
In the example below, column "name" of groupby apply method has the same content as column "year". A similar column with a copy of the "name" values will remain untouched (as expected).
import pandas
import StringIO
csv = """"year","name","percent","sex"
1880,"John",0.081541,"boy"
1880,"William",0.080511,"boy"
1880,"James",0.050057,"boy"
1881,"Charles",0.045167,"boy"
1881,"George",0.043292,"boy"
"""
names = pandas.read_csv(StringIO.StringIO(csv))
names['name2'] = names['name']
grouped = names.groupby('year')
print 'Pandas version', pandas.__version__
print names
print grouped.apply(lambda x:x)
OUTPUT:
Pandas version 0.7.2
year name percent sex name2
0 1880 John 0.081541 boy John
1 1880 William 0.080511 boy William
2 1880 James 0.050057 boy James
3 1881 Charles 0.045167 boy Charles
4 1881 George 0.043292 boy George
year name percent sex name2
0 1880 1880 0.081541 boy John
1 1880 1880 0.080511 boy William
2 1880 1880 0.050057 boy James
3 1881 1881 0.045167 boy Charles
4 1881 1881 0.043292 boy George