第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在保留標(biāo)題的同時(shí)翻轉(zhuǎn) csv 行順序?

如何在保留標(biāo)題的同時(shí)翻轉(zhuǎn) csv 行順序?

慕哥6287543 2022-10-11 21:09:56
我希望能夠翻轉(zhuǎn) csv 文件行但保留標(biāo)題。當(dāng)前的timestamp       open      high       low     close     volume2020-04-14 2805.1001 2851.8501 2805.1001 2846.0601 31133887412020-04-13 2782.4600 2782.4600 2721.1699 2761.6299 5274310000 .....2000-01-04 1455.2200 1455.2200 1397.4301 1399.4200 10090000002000-01-03 1469.2500 1478.0000 1438.3600 1455.2200 931800000期望的結(jié)果timestamp       open      high       low     close     volume2000-01-03 1469.2500 1478.0000 1438.3600 1455.2200 9318000002000-01-04 1455.2200 1455.2200 1397.4301 1399.4200 1009000000.....2020-04-13 2782.4600 2782.4600 2721.1699 2761.6299 52743100002020-04-14 2805.1001 2851.8501 2805.1001 2846.0601 3113388741我已經(jīng)能夠用這個(gè)翻轉(zhuǎn)數(shù)據(jù),但我不能保留標(biāo)題。添加了跳過(guò)標(biāo)題,否則將標(biāo)題放在 csv 文件的底部。當(dāng)前代碼 def reverse_csv():    with open("spx.csv", "r") as infile, open("spx_cleaned.csv", "w") as outfile:    reader = csv.reader(infile)    next(reader, None)  # skip the headers    writer = csv.writer(outfile)    for row in reversed(list(reader)):        # process each row        writer.writerow(row)謝謝!
查看完整描述

3 回答

?
陪伴而非守候

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊

你可以試試下面的嗎?

pd.read_csv('input.csv').iloc[::-1].to_csv('output.csv', index=False)


查看完整回答
反對(duì) 回復(fù) 2022-10-11
?
慕妹3242003

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊

嘗試


import pandas as pd 


df = pd.read_csv('spx.csv')

df = df[::-1].reset_index(drop=True)

df.to_csv('spx_cleaned.csv')


查看完整回答
反對(duì) 回復(fù) 2022-10-11
?
叮當(dāng)貓咪

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊

只需使用 iloc:

df.iloc[::-1]


查看完整回答
反對(duì) 回復(fù) 2022-10-11
  • 3 回答
  • 0 關(guān)注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)