我使用.to_csv()将数据帧列表导出到csv文件中,当我尝试读回数据时,它将合并所有数据帧并仅返回一个数据帧。
mydata:
[ v1 v2
time
2019-08-04 7.308368 4.622069
2019-08-05 6.318558 3.993616
... ... ...
2020-07-31 3.397716 1.914453
2020-08-01 2.232000 1.534888
[364 rows x 2 columns],
v1 v2
time
2019-08-04 0.400307 0.322742
2019-08-05 0.306128 0.229573
... ... ...
2020-07-28 0.405865 0.335051
2020-08-01 0.508580 0.394044
[367 rows x 2 columns],
v1 v2
time
2019-08-01 4.892139 3.420369
2019-08-05 4.375880 3.181351
... ... ...
2019-12-05 NaN NaN
2019-12-09 1.078299 0.590751
[131 rows x 2 columns],
..]
csv文件:
time;v1;v2
2019-08-01;5.004642491294296;2.070262692905746
2019-08-02;6.005581617403156;3.5806659894959636
2019-08-03;5.720055440019435;4.076401038795619
...
time;v1;v2
2019-08-04;7.308368263370739;4.6220686806106
2019-08-05;6.318558302126913;3.9936164101171587
2019-08-06;5.602923231110271;3.455379392672936
...
time;v1;v2
2019-08-07;4.12752721072869;2.4488549880224264
2019-08-08;5.244169560874248;3.150645259745313
...
读取csv文件:
data= pd.read_csv('results.csv', delimiter = ";", index_col=0, header = 0)
数据:
v1 v2
time
2019-08-01 5.004642491294296 2.070262692905746
2019-08-05 6.318558302126913 3.9936164101171587
... ... ...
2020-07-28 18.93710638512659 15.27918513484749
2020-08-01 45.634680485520484 33.58384984534077
**1858 rows × 2 columns**
如何在列表中单独返回数据帧。
答案 0 :(得分:0)
将其保存为泡菜,以保留列表数据类型:
Future<List<Property>> _doSearch () async{
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context){
return MyProgressDialog("Please wait...");
}
);
Response response = await get("https://www.example.com/services/?action=search");
if(response.statusCode == 200){
Navigator.pop(context);
var jsonData = json.decode(response.body);
var res = jsonData["results"];
List<Property> results = [];
for (var p in res){
Property unit = Property(p["property_title"], p["property_image"]);
results.add(unit);
}
print(results.length);
return results;
}else{
Navigator.pop(context);
}
}
再次加载:
import pickle as pkl
df_list = [] # all your dataframes in a list
pkl.dump(df_list, open("your_pkl_file.pkl","wb"))
我认为这比将其另存为csv容易得多,只是您绝对需要将其存储为csv。然后,您必须分别保存每个df,以便在不同的文件中拥有一个干净的工作环境。