Reputation: 899
I'm converting my csv into dataframe using pandas but when printing it it prints index automatically I tried to use
index=false
and
dataframe.drop(['Unnamed 0']
but non worked this is the code
data = pd.read_csv('testlast.csv', sep='\t', index=False)
print(data)
the output looks like
that is how the sentence look like in csv
how to remove those auto generated numbers
Upvotes: 0
Views: 910
Reputation: 863361
Series
and DataFrame
in pandas have always index, reasons are docs:
The axis labeling information in pandas objects serves many purposes:
Identifies data (i.e. provides metadata) using known indicators, important for analysis, visualization, and interactive console display.
Enables automatic and explicit data alignment.
Allows intuitive getting and setting of subsets of the data set.
So for working with data you can ignore it (if not necessary for data processing):
df1 = (df['sentences'].str.split(expand=True)
.stack()
.value_counts()
.rename_axis('a')
.reset_index(name='b'))
Last for avoid write index to file add index=False
parameter to DataFrame.to_csv
:
df1.to_csv(file, index=False)
Upvotes: 1