简体   繁体   中英

How do I remove/change header name with Pandas in Python3?

header = "Visited Websites"
bhistory = pd.read_csv('chrome_history.csv', header= None)
print (bhistory[:10][0])
x = bhistory[:10][0]
df = pd.DataFrame(x)
df.to_csv('chrome_history.csv')

I wrote this code to output the last 10 website I visited and output it in a csv file. However in the final CSV file, the output is:

,0
0,https://datatofish.com/one-python-script-from-another/
1,http://9to5google.com/
2,https://9to5google.com/
3,http://github.com/
4,https://github.com/
5,https://stackoverflow.com/
6,https://www.google.com/search?q=stackoverflow.com&oq=stackoverflow.com+&aqs=chrome..69i58j69i57j0j69i60l3j5i44j69i60.10911j0j4&sourceid=chrome&ie=UTF-8
7,https://www.reddit.com/
8,http://reddit.com/
9,https://reddit.com/

How do I remove or rename ,0 from the first line?

Also how do I add spaces after the row numbers? ie: from 4,https://github.com/ to >> 4, https://github.com/

hiii perhaps use df.to_csv('chrome_history.csv', header=False)

could use numpy-savetxt to have a multi-character delimiter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM