-1

The print result has a serial number, how do I delete it

import pandas as pd
data = pd.read_csv("G:/jeri/1.csv",usecols=['Age'])
print(data)
f = open (r'G:/hello.txt','w')
print (data,file = f)

Open the output txt text to get the result

   Age
0   24
1   29
2   32
3   23
4   58
5   42
6   37
7   42
8   51

0,1,2,3,4,5,6,7,8, I'm a beginner, how do I delete it

jeri teri
  • 73
  • 8
  • 1
    Does this answer your question? [How to avoid Python/Pandas creating an index in a saved csv?](https://stackoverflow.com/questions/20845213/how-to-avoid-python-pandas-creating-an-index-in-a-saved-csv) – buran Oct 07 '21 at 17:16

1 Answers1

0

If you just want the single column, you could also use to_csv() to write the file. For example:

import pandas as pd

df = pd.read_csv("1.csv", usecols=['Age'])
df.to_csv("hello.txt", index=False)
Martin Evans
  • 45,791
  • 17
  • 81
  • 97