Skip to content

pandas.core.groupby.DataFrameGroupBy to_csv method doesn't ouput csv file as expected #4882

Closed
@c0indev3l

Description

@c0indev3l
>>> df1 = pd.DataFrame( { 
    "Name" : ["Alice", "Bob", "Mallory", "Mallory", "Bob" , "Mallory"] , 
    "City" : ["Seattle", "Seattle", "Portland", "Seattle", "Seattle", "Portland"] } )

>>> g1 = df1.groupby( [ "Name" ] )

>>> print g1.head()
               City     Name
Name                        
Alice   0   Seattle    Alice
Bob     1   Seattle      Bob
        4   Seattle      Bob
Mallory 2  Portland  Mallory
        3   Seattle  Mallory
        5  Portland  Mallory

>>> g1.to_csv('out.csv')
g1.to_csv('out.csv')
Out[10]: 
Name
Alice      None
Bob        None
Mallory    None
dtype: object

(Why some data are output to ipython console ?)

>>> !cat out.csv
,City,Name
2,Portland,Mallory
3,Seattle,Mallory
5,Portland,Mallory

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions