1 Pandas中的iloc函数
前面的冒号就是取行数,后面的冒号是取列数:
import pandas as pd
df_train=pd.read_json('./Twibot-20/train.json')
df_test=pd.read_json('./Twibot-20/test.json')
df_train=df_train.iloc[:,[0,1,2,3,5]]
df_test=df_test.iloc[:,[0,1,2,3,5]]
loc表示location的意思;iloc中的loc意思相同,前面的i表示integer,所以它只接受整数作为参数。
2 查看.pt文件内容
在Pytorch中,一个约定俗成的方法是使用.pt扩展的文件格式来保存张量,使用的方法为torch.save() -- 保存张量;
在Pytorch中,使用torch.load()方法加载torch.save()方法保存的文件 -- 加载张量
使用循环查看torch保存的.pt文件网络参数 -- 查看张量文件
import torch # 命令行是逐行立即执行的
content = torch.load('t.pth',map_location=torch.device('cpu') )
print(content.keys()) # keys()
# 之后有其他需求比如要看 key 为 model 的内容有啥
print(content['model'])
# 或者
for parameter in lz.parameters():
print(parameter)