pd.set_option('max_colwidth', -1)
data = pd.read_csv('intC.txt')
print(data)
mysort = data.sort_values(by=['TXBS'], ascending=False)
这是intC.txt文件的样子:
1 个答案:
答案 0 :(得分:0)
您也可以尝试避免KeyError,希望下面的代码能解决您的问题:
import pandas as pd
data = pd.DataFrame([i.split() for i in open("intC.txt", "r").readlines()])
data.columns = data.iloc[0]
data = data.iloc[1: , :]
data['TXBS'] = pd.to_numeric(data['TXBS'], errors='coerce')
mysort = data.sort_values(by=['TXBS'], ascending=False)