简体   繁体   中英

python hdfs writer adds an extra index column to output csv

I need to write a csv to hdfs. Currently i am using hdfs module for doing that.

df = pd.DataFrame(data, columns = ['FirstName','LastName','City'])
d = InsecureClient('http://localhost:50070')
with d.write(path, encoding = 'utf-8', overwrite=True) as writer:
    df.to_csv(writer)

file is succesfully generated, but it adds and extra index column as starting to the csv. I need to have the file with the columns i have specified. how i can remove this index? i could not find any parameter for that.

#current output:
,"FirstName","LastName","City"
0,"John","Doo","New York" 
1,"Jane","Doo","San Francisco"

#expected:
"FirstName","LastName","City"
"John","Doo","New York"
"Jane","Doo","San Francisco"

thanks in advance, clairvoyant

update: using pandas package to create my csv

调用to_csv时将index=False设置(默认为True )。

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