Python df CSV How do I remove default row number

Viewed 458

Screenshot

Hi there! Help needed. Can someone teach me how to remove the numbers by the side? I am trying to print a unique list of towns.

This is what I have so far. Super grateful if you could provide some guidance! Thanks!

import pandas as pd
# Read CSV file into DataFrame df
df = pd.read_csv('towns.csv')
df2 = df[['town']]
df2 = df2.drop_duplicates()
print('List of Towns')
print(df2)
2 Answers

Here is an easy way of doing that.

df = pd.read_csv('towns.csv')
df2 = df[['town']]
 
df2 = df2.reset_index(drop=True)

To print a list of towns without index.

df = pd.read_csv('towns.csv')
df2 = df[['town']]
df2 = df2.drop_duplicates()
list_of_towns = df2.values.tolist()

print('List of Towns')
print( list_of_towns )
Related