|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
此问题,isdkz 大师提供的方法,我运行时会出现“ValueError: DataFrame constructor not properly called!” 错误提示,不知道到底是什么原因,我也觉得代码完全没问题,就是不出结果,
麻烦大师们再帮忙看看,谢谢,具体如下:
桌面文件:webpage.txt文本内容如下:
var r = [["000001","HXCZHH","华夏成长混合","混合型-灵活","HUAXIACHENGZHANGHUNHE"],["000002","HXCZHH","华夏成长混合(后端)","混合型-灵活","HUAXIACHENGZHANGHUNHE"],["000003","ZHKZZZQA","中海可转债债券A","债券型-可转债","ZHONGHAIKEZHUANZHAIZHAIQUANA"],["980003","TPYLGYGDCYZ","太平洋六个月滚动持有债","债券型-长债","TAIPINGYANGLIUGEYUEGUNDONGCHIYOUZHAI"]];
我想得到这个数据帧:
代码 名称首字拼音 名称 类型 其它
"000001" HXCZHH" "华夏成长混合" "混合型-灵活" "HUAXIACHENGZHANGHUNHE"
"000002" "HXCZHH" "华夏成长混合(后端)" "混合型-灵活" "HUAXIACHENGZHANGHUNHE"
"000003" ZHKZZZQA" "中海可转债债券A" "债券型-可转债" "ZHONGHAIKEZHUANZHAIZHAIQUANA"
"980003" "TPYLGYGDCYZ" "太平洋六个月滚动持有债" "债券型-长债" "TAIPINGYANGLIUGEYUEGUNDONGCHIYOUZHAI"
根据 isdkz 大师提供的方法(最下面是代码),我的会出现“ValueError: DataFrame constructor not properly called!” 错误提示
import re
import pandas as pd
with open(r'C:\Users\ppp\Desktop\webpage.txt', "r") as f:
#print(type(f))
response = f.read()
data_list = re.findall(r'\[(?:.*)\]', response)
df = pd.DataFrame(data_list[0], columns=["代码" ,"名称首字拼音","名称","类型", "其它"])
print(df)
import re
import pandas as pd
with open(r'C:\Users\OYF\Desktop\ppp\webpage.txt', "r") as f:
response = f.read()
data_list = re.findall(r'\[(.*)\]', response)
df = pd.DataFrame(eval(data_list[0]), columns=["代码" ,"名称首字拼音","名称","类型", "其它"])
print(df)
|
|