简体   繁体   中英

Deleting an unnamed column from a csv file Pandas Python

I ma trying to write a code that deletes the unnamed column , that comes right before Unix Timestamp . After deleting I will save the modified dataframe into data.csv . How would I be able to get the Expected Output below?

import pandas ads pd 

data = pd.read_csv('data.csv')
data.drop('')
data.to_csv('data.csv')

data.csv file

,Unix Timestamp,Date,Symbol,Open,High,Low,Close,Volume
0,1635686220,2021-10-31 13:17:00,BTCUSD,60638.0,60640.0,60636.0,60638.0,0.4357009185659157
1,1635686160,2021-10-31 13:16:00,BTCUSD,60568.0,60640.0,60568.0,60638.0,3.9771881707839967
2,1635686100,2021-10-31 13:15:00,BTCUSD,60620.0,60633.0,60565.0,60568.0,1.3977284440628714

Updated csv (Expected Output):

Unix Timestamp,Date,Symbol,Open,High,Low,Close,Volume
1635686220,2021-10-31 13:17:00,BTCUSD,60638.0,60640.0,60636.0,60638.0,0.4357009185659157
1635686160,2021-10-31 13:16:00,BTCUSD,60568.0,60640.0,60568.0,60638.0,3.9771881707839967
1635686100,2021-10-31 13:15:00,BTCUSD,60620.0,60633.0,60565.0,60568.0,1.3977284440628714

在此处输入图片说明

This is the index. Use index=False in to_csv .

data.to_csv('data.csv', index=False)

将第一列设置为 index df = pd.read_csv('data.csv', index_col=0)并在写入结果时设置index=False

you can follow below code.it will take column from 1st position and then you can save that df to csv without index values.

df = df.iloc[:,1:]
df.to_csv("data.csv",index=False)

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