[英]Python df CSV How do I remove default row number
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)
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 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.