Python, Pandas : write content of DataFrame into text File

前端 未结 7 1858
再見小時候
再見小時候 2020-11-27 11:49

I have pandas DataFrame like this

        X    Y  Z    Value 
0      18   55  1      70   
1      18   55  2      67 
2      18   57  2      75     
3      1         


        
相关标签:
7条回答
  • 2020-11-27 12:34

    You can use pandas.DataFrame.to_csv(), and setting both index and header to False:

    In [97]: print df.to_csv(sep=' ', index=False, header=False)
    18 55 1 70
    18 55 2 67
    18 57 2 75
    18 58 1 35
    19 54 2 70
    

    pandas.DataFrame.to_csv can write to a file directly, for more info you can refer to the docs linked above.

    0 讨论(0)
提交回复
热议问题