How to convert independent output lists to a dataframe - python

Hope you are having a great weekend. My problem is as follows:
For my designed model i am getting the following predictions:
[0.3182012736797333, 0.6817986965179443, 0.5067878365516663, 0.49321213364601135, 0.4795221984386444, 0.520477831363678, 0.532780110836029, 0.46721988916397095, 0.3282901346683502, 0.6717098355293274]
[0.362120658159256, 0.6378793120384216, 0.5134761929512024, 0.4865237772464752, 0.46048662066459656, 0.539513349533081, 0.5342788100242615, 0.4657211899757385, 0.34932515025138855, 0.6506748199462891]
[0.3647380471229553, 0.6352618932723999, 0.5087167620658875, 0.49128326773643494, 0.4709164798259735, 0.5290834903717041, 0.5408024787902832, 0.4591975510120392, 0.37024226784706116, 0.6297577023506165]
[0.43765324354171753, 0.5623468160629272, 0.505147397518158, 0.49485257267951965, 0.45281311869621277, 0.5471869111061096, 0.5416161417961121, 0.45838382840156555, 0.3789178133010864, 0.6210821866989136]
[0.44772887229919434, 0.5522711277008057, 0.5119441151618958, 0.48805591464042664, 0.46322566270828247, 0.5367743372917175, 0.5402485132217407, 0.45975151658058167, 0.4145151972770691, 0.5854847431182861]
[0.35674020648002625, 0.6432597637176514, 0.48104971647262573, 0.5189502835273743, 0.4554695188999176, 0.54453045129776, 0.5409557223320007, 0.45904430747032166, 0.3258989453315735, 0.6741010546684265]
[0.3909384310245514, 0.609061598777771, 0.4915180504322052, 0.5084819793701172, 0.45033228397369385, 0.5496677160263062, 0.5267384052276611, 0.47326159477233887, 0.34493446350097656, 0.6550655364990234]
[0.32971733808517456, 0.6702827215194702, 0.5224012732505798, 0.47759872674942017, 0.4692566692829132, 0.5307433605194092, 0.5360044836997986, 0.4639955163002014, 0.41811054944992065, 0.5818894505500793]
[0.37096619606018066, 0.6290338039398193, 0.5165190100669861, 0.4834809899330139, 0.4739859998226166, 0.526013970375061, 0.5340168476104736, 0.46598318219184875, 0.3438771069049835, 0.6561229228973389]
[0.4189890921115875, 0.5810109376907349, 0.52749103307724, 0.47250890731811523, 0.44485437870025635, 0.5551456212997437, 0.5398098230361938, 0.46019014716148376, 0.3739124536514282, 0.6260875463485718]
[0.3979812562465668, 0.6020187139511108, 0.5050275325775146, 0.49497246742248535, 0.4653399884700775, 0.5346599817276001, 0.537341833114624, 0.4626581072807312, 0.33742010593414307, 0.6625799536705017]
[0.368088960647583, 0.631911039352417, 0.49925288558006287, 0.5007471442222595, 0.4547160863876343, 0.545283854007721, 0.5408452749252319, 0.45915472507476807, 0.4053747355937958, 0.5946252346038818]
As you can see they are independent lists. I want to convert these lists into a dataframe. Although they are independent, they are coming out of a for loop, so i cannot append them because they are not coming at once.

Use:
data = [[0.3182012736797333, 0.6817986965179443, 0.5067878365516663, 0.49321213364601135, 0.4795221984386444, 0.520477831363678, 0.532780110836029, 0.46721988916397095, 0.3282901346683502, 0.6717098355293274],
[0.362120658159256, 0.6378793120384216, 0.5134761929512024, 0.4865237772464752, 0.46048662066459656, 0.539513349533081, 0.5342788100242615, 0.4657211899757385, 0.34932515025138855, 0.6506748199462891],
[0.3647380471229553, 0.6352618932723999, 0.5087167620658875, 0.49128326773643494, 0.4709164798259735, 0.5290834903717041, 0.5408024787902832, 0.4591975510120392, 0.37024226784706116, 0.6297577023506165],
[0.43765324354171753, 0.5623468160629272, 0.505147397518158, 0.49485257267951965, 0.45281311869621277, 0.5471869111061096, 0.5416161417961121, 0.45838382840156555, 0.3789178133010864, 0.6210821866989136],
[0.44772887229919434, 0.5522711277008057, 0.5119441151618958, 0.48805591464042664, 0.46322566270828247, 0.5367743372917175, 0.5402485132217407, 0.45975151658058167, 0.4145151972770691, 0.5854847431182861],
[0.35674020648002625, 0.6432597637176514, 0.48104971647262573, 0.5189502835273743, 0.4554695188999176, 0.54453045129776, 0.5409557223320007, 0.45904430747032166, 0.3258989453315735, 0.6741010546684265],
[0.3909384310245514, 0.609061598777771, 0.4915180504322052, 0.5084819793701172, 0.45033228397369385, 0.5496677160263062, 0.5267384052276611, 0.47326159477233887, 0.34493446350097656, 0.6550655364990234],
[0.32971733808517456, 0.6702827215194702, 0.5224012732505798, 0.47759872674942017, 0.4692566692829132, 0.5307433605194092, 0.5360044836997986, 0.4639955163002014, 0.41811054944992065, 0.5818894505500793],
[0.37096619606018066, 0.6290338039398193, 0.5165190100669861, 0.4834809899330139, 0.4739859998226166, 0.526013970375061, 0.5340168476104736, 0.46598318219184875, 0.3438771069049835, 0.6561229228973389],
[0.4189890921115875, 0.5810109376907349, 0.52749103307724, 0.47250890731811523, 0.44485437870025635, 0.5551456212997437, 0.5398098230361938, 0.46019014716148376, 0.3739124536514282, 0.6260875463485718],
[0.3979812562465668, 0.6020187139511108, 0.5050275325775146, 0.49497246742248535, 0.4653399884700775, 0.5346599817276001, 0.537341833114624, 0.4626581072807312, 0.33742010593414307, 0.6625799536705017],
[0.368088960647583, 0.631911039352417, 0.49925288558006287, 0.5007471442222595, 0.4547160863876343, 0.545283854007721, 0.5408452749252319, 0.45915472507476807, 0.4053747355937958, 0.5946252346038818]]
# Create this before your for loop
df = pd.DataFrame(columns = range(10))
for pred_list in data:
#Add this within your for loop
df = df.append(pd.Series(pred_list), ignore_index=True)
output:

Related

Cannot Convert list of list using pandas

This is my Data from the api from the looks of it, it is a list of list.
with ApiClient(configuration) as api_client:
api_instance = MetricsApi(api_client)
response = api_instance.query_metrics(
_from=int(yesterday_start_dt.timestamp()),
to=int(yesterday_end_dt.timestamp()),
query="default_zero(sum:trace.servlet.request.hits{env:prd-main,service:api}.as_rate())",
)
result = response['series'][0]['pointlist']
print(result)
[[1648339200000.0, 1105.8433333333332], [1648339500000.0, 1093.3266666666666], [1648339800000.0, 1076.92], [1648340100000.0, 1059.5133333333333], [1648340400000.0, 1053.8966666666668], [1648340700000.0, 1041.2166666666667], [1648341000000.0, 1055.0533333333333], [1648341300000.0, 1037.8933333333334], [1648341600000.0, 1015.4], [1648341900000.0, 1003.3233333333334], [1648342200000.0, 1017.02], [1648342500000.0, 1017.7766666666666], [1648342800000.0, 1011.0333333333333], [1648343100000.0, 993.9366666666666], [1648343400000.0, 973.9733333333334], [1648343700000.0, 967.8433333333334], [1648344000000.0, 933.2166666666667], [1648344300000.0, 945.0833333333334], [1648344600000.0, 905.2166666666667], [1648344900000.0, 923.9966666666667], [1648345200000.0, 925.4633333333334], [1648345500000.0, 915.5533333333333], [1648345800000.0, 918.8966666666666], [1648346100000.0, 883.6], [1648346400000.0, 908.9166666666666], [1648346700000.0, 856.7333333333333], [1648347000000.0, 873.01], [1648347300000.0, 833.99], [1648347600000.0, 846.5466666666666], [1648347900000.0, 820.7833333333333], [1648348200000.0, 821.4633333333334], [1648348500000.0, 812.8633333333333], [1648348800000.0, 817.78], [1648349100000.0, 821.91], [1648349400000.0, 791.17], [1648349700000.0, 780.3066666666666], [1648350000000.0, 803.4633333333334], [1648350300000.0, 781.9033333333333], [1648350600000.0, 759.4933333333333], [1648350900000.0, 746.11], [1648351200000.0, 731.3133333333334], [1648351500000.0, 724.0533333333333], [1648351800000.0, 710.56], [1648352100000.0, 722.87], [1648352400000.0, 677.5266666666666], [1648352700000.0, 681.7833333333333], [1648353000000.0, 679.9233333333333], [1648353300000.0, 650.6466666666666], [1648353600000.0, 663.78], [1648353900000.0, 650.8133333333334], [1648354200000.0, 645.9133333333333], [1648354500000.0, 642.4566666666667], [1648354800000.0, 627.93], [1648355100000.0, 616.65], [1648355400000.0, 609.94], [1648355700000.0, 602.0733333333334], [1648356000000.0, 581.6133333333333], [1648356300000.0, 592.48], [1648356600000.0, 593.4], [1648356900000.0, 582.2633333333333], [1648357200000.0, 598.3766666666667], [1648357500000.0, 589.99], [1648357800000.0, 577.7433333333333], [1648358100000.0, 570.1733333333333], [1648358400000.0, 592.58], [1648358700000.0, 578.2533333333333], [1648359000000.0, 586.8833333333333], [1648359300000.0, 590.4033333333333], [1648359600000.0, 601.49], [1648359900000.0, 594.8], [1648360200000.0, 609.01], [1648360500000.0, 620.08], [1648360800000.0, 642.6466666666666], [1648361100000.0, 635.93], [1648361400000.0, 638.42], [1648361700000.0, 645.2], [1648362000000.0, 650.42], [1648362300000.0, 667.88], [1648362600000.0, 689.3666666666667], [1648362900000.0, 694.4433333333334], [1648363200000.0, 690.3933333333333], [1648363500000.0, 710.55], [1648363800000.0, 706.3], [1648364100000.0, 729.5], [1648364400000.0, 771.36], [1648364700000.0, 754.03], [1648365000000.0, 771.4866666666667], [1648365300000.0, 767.52], [1648365600000.0, 779.4133333333333], [1648365900000.0, 800.4266666666666], [1648366200000.0, 788.41], [1648366500000.0, 806.8666666666667], [1648366800000.0, 805.7466666666667], [1648367100000.0, 815.2433333333333], [1648367400000.0, 828.0833333333334], [1648367700000.0, 817.1966666666667], [1648368000000.0, 879.4733333333334], [1648368300000.0, 840.7933333333333], [1648368600000.0, 846.4266666666666], [1648368900000.0, 848.1266666666667], [1648369200000.0, 836.9066666666666], [1648369500000.0, 845.4966666666667], [1648369800000.0, 863.5033333333333], [1648370100000.0, 867.1866666666666], [1648370400000.0, 866.74], [1648370700000.0, 863.8066666666666], [1648371000000.0, 882.38], [1648371300000.0, 876.0233333333333], [1648371600000.0, 905.3366666666667], [1648371900000.0, 879.8066666666666], [1648372200000.0, 878.37], [1648372500000.0, 876.9333333333333], [1648372800000.0, 868.1533333333333], [1648373100000.0, 882.12], [1648373400000.0, 896.9233333333333], [1648373700000.0, 872.84], [1648374000000.0, 880.71], [1648374300000.0, 894.8066666666666], [1648374600000.0, 873.7266666666667], [1648374900000.0, 891.0033333333333], [1648375200000.0, 927.2433333333333], [1648375500000.0, 905.52], [1648375800000.0, 895.0233333333333], [1648376100000.0, 895.86], [1648376400000.0, 899.3133333333334], [1648376700000.0, 920.22], [1648377000000.0, 937.68], [1648377300000.0, 916.46], [1648377600000.0, 926.6833333333333], [1648377900000.0, 936.4366666666666], [1648378200000.0, 947.6133333333333], [1648378500000.0, 957.7133333333334], [1648378800000.0, 989.1133333333333], [1648379100000.0, 959.0766666666667], [1648379400000.0, 963.5133333333333], [1648379700000.0, 978.3466666666667], [1648380000000.0, 1017.78], [1648380300000.0, 989.7566666666667], [1648380600000.0, 1023.4633333333334], [1648380900000.0, 1033.7166666666667], [1648381200000.0, 1025.1933333333334], [1648381500000.0, 1045.8633333333332], [1648381800000.0, 1063.6133333333332], [1648382100000.0, 1078.45], [1648382400000.0, 1116.3866666666668], [1648382700000.0, 1098.9766666666667], [1648383000000.0, 1101.29], [1648383300000.0, 1127.6], [1648383600000.0, 1102.5233333333333], [1648383900000.0, 1140.84], [1648384200000.0, 1169.23], [1648384500000.0, 1158.6], [1648384800000.0, 1180.01], [1648385100000.0, 1190.43], [1648385400000.0, 1207.3733333333332], [1648385700000.0, 1212.7666666666667], [1648386000000.0, 1244.17], [1648386300000.0, 1245.3166666666666], [1648386600000.0, 1240.69], [1648386900000.0, 1270.33], [1648387200000.0, 1277.8033333333333], [1648387500000.0, 1270.5966666666666], [1648387800000.0, 1304.4266666666667], [1648388100000.0, 1295.6933333333334], [1648388400000.0, 1322.3066666666666], [1648388700000.0, 1351.41], [1648389000000.0, 1339.9566666666667], [1648389300000.0, 1353.2966666666666], [1648389600000.0, 1398.45], [1648389900000.0, 1378.21], [1648390200000.0, 1361.0933333333332], [1648390500000.0, 1404.0833333333333], [1648390800000.0, 1394.6466666666668], [1648391100000.0, 1391.1366666666668], [1648391400000.0, 1450.0], [1648391700000.0, 1438.97], [1648392000000.0, 1411.83], [1648392300000.0, 1432.8233333333333], [1648392600000.0, 1473.3966666666668], [1648392900000.0, 1491.0166666666667], [1648393200000.0, 1509.8766666666668], [1648393500000.0, 1488.6566666666668], [1648393800000.0, 1488.4933333333333], [1648394100000.0, 1511.4466666666667], [1648394400000.0, 1508.3566666666666], [1648394700000.0, 1507.8966666666668], [1648395000000.0, 1515.8633333333332], [1648395300000.0, 1517.3], [1648395600000.0, 1528.81], [1648395900000.0, 1546.1266666666668], [1648396200000.0, 1554.57], [1648396500000.0, 1584.0333333333333], [1648396800000.0, 1584.45], [1648397100000.0, 1590.4633333333334], [1648397400000.0, 1580.0066666666667], [1648397700000.0, 1596.3833333333334], [1648398000000.0, 1571.96], [1648398300000.0, 1583.8233333333333], [1648398600000.0, 1618.7033333333334], [1648398900000.0, 1588.12], [1648399200000.0, 1599.56], [1648399500000.0, 1604.1833333333334], [1648399800000.0, 1621.5666666666666], [1648400100000.0, 1598.98], [1648400400000.0, 1627.02], [1648400700000.0, 1612.7833333333333], [1648401000000.0, 1612.2433333333333], [1648401300000.0, 1572.89], [1648401600000.0, 1601.8933333333334], [1648401900000.0, 1612.5366666666666], [1648402200000.0, 1608.7266666666667], [1648402500000.0, 1594.4366666666667], [1648402800000.0, 1614.3366666666666], [1648403100000.0, 1649.0733333333333], [1648403400000.0, 1627.12], [1648403700000.0, 1644.9633333333334], [1648404000000.0, 1653.9033333333334], [1648404300000.0, 1636.6966666666667], [1648404600000.0, 1639.5733333333333], [1648404900000.0, 1627.3866666666668], [1648405200000.0, 1626.3733333333332], [1648405500000.0, 1616.7966666666666], [1648405800000.0, 1667.2933333333333], [1648406100000.0, 1637.0733333333333], [1648406400000.0, 1654.6366666666668], [1648406700000.0, 1673.9566666666667], [1648407000000.0, 1658.4466666666667], [1648407300000.0, 1650.6766666666667], [1648407600000.0, 1662.1933333333334], [1648407900000.0, 1686.9733333333334], [1648408200000.0, 1623.0433333333333], [1648408500000.0, 1630.2866666666666], [1648408800000.0, 1599.0466666666666], [1648409100000.0, 1624.8033333333333], [1648409400000.0, 1606.0333333333333], [1648409700000.0, 1594.15], [1648410000000.0, 1557.1333333333334], [1648410300000.0, 1630.6133333333332], [1648410600000.0, 1591.93], [1648410900000.0, 1579.5733333333333], [1648411200000.0, 1585.1466666666668], [1648411500000.0, 1565.6166666666666], [1648411800000.0, 1566.3366666666666], [1648412100000.0, 1544.1866666666667], [1648412400000.0, 1511.8166666666666], [1648412700000.0, 1525.2333333333333], [1648413000000.0, 1505.57], [1648413300000.0, 1462.9033333333334], [1648413600000.0, 1478.0733333333333], [1648413900000.0, 1460.76], [1648414200000.0, 1504.59], [1648414500000.0, 1460.3366666666666], [1648414800000.0, 1445.9366666666667], [1648415100000.0, 1410.0033333333333], [1648415400000.0, 1412.8466666666666], [1648415700000.0, 1364.8933333333334], [1648416000000.0, 1348.4], [1648416300000.0, 1338.3333333333333], [1648416600000.0, 1326.8633333333332], [1648416900000.0, 1276.24], [1648417200000.0, 1310.0333333333333], [1648417500000.0, 1285.63], [1648417800000.0, 1244.14], [1648418100000.0, 1258.38], [1648418400000.0, 1218.37], [1648418700000.0, 1182.0266666666666], [1648419000000.0, 1196.8133333333333], [1648419300000.0, 1144.54], [1648419600000.0, 1165.62], [1648419900000.0, 1122.0166666666667], [1648420200000.0, 1112.6766666666667], [1648420500000.0, 1102.6], [1648420800000.0, 1095.6966666666667], [1648421100000.0, 1056.63], [1648421400000.0, 1074.5066666666667], [1648421700000.0, 1047.5933333333332], [1648422000000.0, 1057.2633333333333], [1648422300000.0, 1043.99], [1648422600000.0, 1003.4033333333333], [1648422900000.0, 1022.2633333333333], [1648423200000.0, 1016.59], [1648423500000.0, 997.4466666666667], [1648423800000.0, 988.7666666666667], [1648424100000.0, 966.1666666666666], [1648424400000.0, 991.21], [1648424700000.0, 977.6633333333333], [1648425000000.0, 959.64], [1648425300000.0, 961.6989966555184]]
But when i try to convert into pandas it convert but the result is what i expected, i expected that the dataframe will make two columns.
with ApiClient(configuration) as api_client:
api_instance = MetricsApi(api_client)
response = api_instance.query_metrics(
_from=int(yesterday_start_dt.timestamp()),
to=int(yesterday_end_dt.timestamp()),
query="default_zero(sum:trace.servlet.request.hits{env:prd-main,service:api}.as_rate())",
)
result = response['series'][0]['pointlist']
df = pd.DataFrame(result)
print(df)
0
0 [1648339200000.0, 1105.8433333333332]
1 [1648339500000.0, 1093.3266666666666]
2 [1648339800000.0, 1076.92]
3 [1648340100000.0, 1059.5133333333333]
4 [1648340400000.0, 1053.8966666666668]
.. ...
283 [1648424100000.0, 966.1666666666666]
284 [1648424400000.0, 991.21]
285 [1648424700000.0, 977.6633333333333]
286 [1648425000000.0, 959.64]
287 [1648425300000.0, 961.6989966555184]
[288 rows x 1 columns]
As I pointed out in the comment referring to another answer, here how you may do it.
columns = ['point 1', 'point 2']
result = response['series'][0]['pointlist']
df = pd.DataFrame(result,columns=columns)
If you want the first elements of sublists to be in one column, I suggest you create an intermediate np.array and then reshape it into the needed output.
array_results=np.array(results)
df=pd.DataFrame(array_results.reshape(2, len(results)))
following few samples of 'results', here are my outputs

How to optimize PRAW and pandas data collection to make it more pythonic?

I am using PRAW to get data from Reddit and created this function to do so on multiple subreddits.
It works, however, I am working on a more concise/pythonic version but can't figure out how I can create a single "for loop", doing the job of the 3 below.
subs = r.subreddit('Futurology+wallstreetbets+DataIsBeautiful+RenewableEnergy+Bitcoin')
#This function aim to scrap data from a list of subreddit.
#From these subreddit, I would like to get the #new, #hot and #rising posts
def get_data(size_new, size_hot, size_rising, subs_number):
posts = []
followers = []
targeted_date = '14-11-20 12:00:00'
targeted_date = datetime.datetime.strptime(targeted_date, '%d-%m-%y %H:%M:%S')
#getting x new posts
for subreddit in subs.new(limit = size_new):
date = subreddit.created
date = datetime.datetime.fromtimestamp(date)
if date >= targeted_date:
posts.append([date, subreddit.subreddit, subreddit.title, subreddit.selftext])
#getting x hot posts
for subreddit in subs.hot(limit = size_hot):
date = subreddit.created
date = datetime.datetime.fromtimestamp(date)
if date >= targeted_date:
posts.append([date, subreddit.subreddit, subreddit.title, subreddit.selftext])
#getting x rising posts
for subreddit in subs.rising(limit = size_rising):
date = subreddit.created
date = datetime.datetime.fromtimestamp(date)
if date >= targeted_date:
posts.append([date, subreddit.subreddit, subreddit.title, subreddit.selftext])
#getting subreddit subscribers number
for sub_name in subs_2:
for submission in r.subreddit(sub_name).hot(limit = 1):
followers.append([submission.subreddit, r.subreddit(sub_name).subscribers])
#creating 2 df
df_1 = pd.DataFrame(followers, columns = ['subreddit','subscribers'])
df = pd.DataFrame(posts, columns = ['date', 'subreddit', 'title', 'text']).drop_duplicates().sort_values(by = ['date']).reset_index(drop = True)
#concat the 2 df together
df = df.join(df_1.set_index('subreddit'), on = 'subreddit')
df = df[["date", "subreddit", "subscribers", "title", 'text']]
df = df[df.subscribers > subs_number].reset_index(drop = True)
return df
My request: how could it be more concise/optimized? What methodology are you using to make your code more readable or even better, optimize it for run time/computational resources?
Thank you
There are various principles to make better code, and various tools to use to find the 'code smells' that may be lurking in your code.
DRY - Don't Repeat Yourself
KISS - keep it stupid simple
SOLID
etc...
Taking a dive into the code that you posted using some of the principles on a surface level would refactor some of your code into looking like:
subs = r.subreddit('Futurology+wallstreetbets+DataIsBeautiful+RenewableEnergy+Bitcoin')
# check that the date is greater than the target date
# return true/false
def check_date(subreddit, targeted_date):
return subreddit.created >= targeted_date:
# get specific post data
def get_post_data(subreddit):
return [subreddit.created, subreddit.subreddit, subreddit.title, subreddit.selftext]
# get posts by sort type
def get_subreddit_post_types(subreddit_sort, targeted_date):
return [get_post_data(subreddit) for subreddit in subreddit_sort if check_date(subreddit, targeted_date)]
#This function aim to scrap data from a list of subreddit.
#From these subreddit, I would like to get the #new, #hot and #rising posts
def get_data(size_new, size_hot, size_rising, subs_number):
targeted_date = '14-11-20 12:00:00'
targeted_date = datetime.datetime.strptime(targeted_date, '%d-%m-%y %H:%M:%S').timestamp()
posts = []
followers = []
#getting x new posts
posts.extend(get_subreddit_post_types(subs.new(limit = size_new), targeted_date))
#getting x hot posts
posts.extend(get_subreddit_post_types(subs.hot(limit = size_hot), targeted_date))
#getting x rising posts
posts.extend(get_subreddit_post_types(subs.rising(limit = size_rising), targeted_date))
#getting subreddit subscribers number
for sub_name in subs_2:
for submission in r.subreddit(sub_name).hot(limit = 1):
followers.append([submission.subreddit, r.subreddit(sub_name).subscribers])
#creating 2 df
df_1 = pd.DataFrame(followers, columns = ['subreddit','subscribers'])
df = pd.DataFrame(posts, columns = ['date', 'subreddit', 'title', 'text']).drop_duplicates().sort_values(by = ['date']).reset_index(drop = True)
#concat the 2 df together
df = df.join(df_1.set_index('subreddit'), on = 'subreddit')
df = df[["date", "subreddit", "subscribers", "title", 'text']]
df = df[df.subscribers > subs_number].reset_index(drop = True)
return df
As for better optimizing your computational resources (what are you trying to optimize memory or runtime)? The same process applies to either is to look at your code to see what can be changed to decrease one versus the other.
From looking at your code something that would generally optimize what you wrote would be to look at what are the 'duplicate' posts that you are getting. If you could remove the duplicate check (as each of the hot/rising/new get posts from similar date ranges, but hot/rising may be completely encompassed inside of new) call from the posts that you gathered, so that you don't have to check that they are different, and possibly remove hot/rising calls (because those posts may be encompassed in new).

How to get a certain value from a text file

I want to get a value from an API. However I am unable to tell Python what I want to do.
This is my current code:
response = requests.get('https://sms-service-online.com/api/getServicesAndCost/?country=0&operator=any&lang=en')
data = response.json()
plain = data["data"]
However the data which I want to display in my script is in the ["data"] part of the json. It is kind of a json inside a json.
For example: with
print(plain)
I would recieve this data:
[{"cost":"0.45","id":0,"servise":"VK.com","serviseImg":"bg-vk","number":"Numbers: 3047","value":"vk"},{"cost":"0.07","id":1,"servise":"OK.ru","serviseImg":"bg-ok","number":"Numbers: 14397","value":"ok"},{"cost":"0.15","id":2,"servise":"Whatsapp","serviseImg":"bg-wa","number":"Numbers: 17610","value":"wa"},{"cost":"0.18","id":3,"servise":"Viber","serviseImg":"bg-vi","number":"Numbers: 413","value":"vi"},{"cost":"0.00","id":4,"servise":"Telegram","serviseImg":"bg-tg","number":"Numbers: 0","value":"tg"},{"cost":"0.30","id":5,"servise":"WeChat","serviseImg":"bg-wb","number":"Numbers: 28389","value":"wb"},{"cost":"0.15","id":6,"servise":"Google,youtube,Gmail","serviseImg":"bg-go","number":"Numbers: 15419","value":"go"},{"cost":"0.11","id":7,"servise":"avito","serviseImg":"bg-av","number":"Numbers: 17379","value":"av"},{"cost":"0.07","id":8,"servise":"facebook","serviseImg":"bg-fb","number":"Numbers: 21636","value":"fb"},{"cost":"0.03","id":9,"servise":"Twitter","serviseImg":"bg-tw","number":"Numbers: 26864","value":"tw"},{"cost":"0.05","id":10,"servise":"Uber","serviseImg":"bg-ub","number":"Numbers: 20975","value":"ub"},{"cost":"0.22","id":11,"servise":"Qiwi","serviseImg":"bg-qw","number":"Numbers: 20371","value":"qw"},{"cost":"0.02","id":12,"servise":"Gett","serviseImg":"bg-gt","number":"Numbers: 28501","value":"gt"},{"cost":"0.00","id":13,"servise":"OLX","serviseImg":"bg-sn","number":"Numbers: 0","value":"sn"},{"cost":"0.14","id":14,"servise":"Instagram","serviseImg":"bg-ig","number":"Numbers: 3799","value":"ig"},{"cost":"0.00","id":15,"servise":"Hezzl","serviseImg":"bg-ss","number":"Numbers: 0","value":"ss"},{"cost":"0.07","id":16,"servise":"\u042e\u043b\u0430","serviseImg":"bg-ym","number":"Numbers: 17597","value":"ym"},{"cost":"0.03","id":17,"servise":"Mail.ru","serviseImg":"bg-ma","number":"Numbers: 17936","value":"ma"},{"cost":"0.03","id":18,"servise":"Microsoft","serviseImg":"bg-mm","number":"Numbers: 3830","value":"mm"},{"cost":"0.03","id":19,"servise":"Airbnb","serviseImg":"bg-uk","number":"Numbers: 28266","value":"uk"},{"cost":"0.00","id":20,"servise":"Line messenger","serviseImg":"bg-me","number":"Numbers: 0","value":"me"},{"cost":"0.03","id":21,"servise":"Yahoo","serviseImg":"bg-mb","number":"Numbers: 19077","value":"mb"},{"cost":"0.00","id":22,"servise":"Drugvokrug.ru","serviseImg":"bg-we","number":"Numbers: 0","value":"we"},{"cost":"0.05","id":23,"servise":"5ka.ru","serviseImg":"bg-bd","number":"Numbers: 27541","value":"bd"},{"cost":"0.00","id":24,"servise":"HQ Trivia","serviseImg":"bg-kp","number":"Numbers: 0","value":"kp"},{"cost":"0.65","id":25,"servise":"Delivery Club","serviseImg":"bg-dt","number":"Numbers: 26812","value":"dt"},{"cost":"0.03","id":26,"servise":"Yandex","serviseImg":"bg-ya","number":"Numbers: 20944","value":"ya"},{"cost":"0.05","id":27,"servise":"Steam","serviseImg":"bg-mt","number":"Numbers: 28121","value":"mt"},{"cost":"0.04","id":28,"servise":"Tinder","serviseImg":"bg-oi","number":"Numbers: 27478","value":"oi"},{"cost":"0.02","id":29,"servise":"Mamba, MeetMe","serviseImg":"bg-fd","number":"Numbers: 25328","value":"fd"},{"cost":"0.00","id":30,"servise":"Dent","serviseImg":"bg-zz","number":"Numbers: 0","value":"zz"},{"cost":"0.07","id":31,"servise":"KakaoTalk","serviseImg":"bg-kt","number":"Numbers: 27823","value":"kt"},{"cost":"0.04","id":32,"servise":"AOL","serviseImg":"bg-pm","number":"Numbers: 23369","value":"pm"},{"cost":"0.02","id":33,"servise":"LinkedIN","serviseImg":"bg-tn","number":"Numbers: 32192","value":"tn"},{"cost":"0.03","id":34,"servise":"Tencent QQ","serviseImg":"bg-qq","number":"Numbers: 27883","value":"qq"},{"cost":"0.06","id":35,"servise":"Magnit","serviseImg":"bg-mg","number":"Numbers: 993","value":"mg"},{"cost":"0.00","id":36,"servise":"pof.com","serviseImg":"bg-pf","number":"Numbers: 0","value":"pf"},{"cost":"0.03","id":37,"servise":"Yalla","serviseImg":"bg-yl","number":"Numbers: 27822","value":"yl"},{"cost":"0.00","id":38,"servise":"kolesa.kz","serviseImg":"bg-kl","number":"Numbers: 0","value":"kl"},{"cost":"0.03","id":39,"servise":"premium.one","serviseImg":"bg-po","number":"Numbers: 25869","value":"po"},{"cost":"0.07","id":40,"servise":"Naver","serviseImg":"bg-nv","number":"Numbers: 27582","value":"nv"},{"cost":"0.03","id":41,"servise":"Netflix","serviseImg":"bg-nf","number":"Numbers: 27715","value":"nf"},{"cost":"0.00","id":42,"servise":"icq","serviseImg":"bg-iq","number":"Numbers: 0","value":"iq"},{"cost":"0.00","id":43,"servise":"Onlinerby","serviseImg":"bg-ob","number":"Numbers: 0","value":"ob"},{"cost":"0.00","id":44,"servise":"kufarby","serviseImg":"bg-kb","number":"Numbers: 0","value":"kb"},{"cost":"0.03","id":45,"servise":"Imo","serviseImg":"bg-im","number":"Numbers: 25198","value":"im"},{"cost":"0.00","id":46,"servise":"Michat","serviseImg":"bg-mc","number":"Numbers: 0","value":"mc"},{"cost":"0.03","id":47,"servise":"Discord","serviseImg":"bg-ds","number":"Numbers: 22011","value":"ds"},{"cost":"0.00","id":48,"servise":"Seosprint","serviseImg":"bg-vv","number":"Numbers: 0","value":"vv"},{"cost":"0.00","id":49,"servise":"Monobank","serviseImg":"bg-ji","number":"Numbers: 0","value":"ji"},{"cost":"0.03","id":50,"servise":"TikTok\/Douyin","serviseImg":"bg-lf","number":"Numbers: 26299","value":"lf"},{"cost":"0.00","id":51,"servise":"Ukrnet","serviseImg":"bg-hu","number":"Numbers: 0","value":"hu"},{"cost":"0.00","id":52,"servise":"Skout","serviseImg":"bg-wg","number":"Numbers: 0","value":"wg"},{"cost":"0.00","id":53,"servise":"EasyPay","serviseImg":"bg-rz","number":"Numbers: 0","value":"rz"},{"cost":"0.00","id":54,"servise":"Q12 Trivia","serviseImg":"bg-vf","number":"Numbers: 0","value":"vf"},{"cost":"0.00","id":55,"servise":"Pyro Music","serviseImg":"bg-ny","number":"Numbers: 0","value":"ny"},{"cost":"0.00","id":56,"servise":"Wolt","serviseImg":"bg-rr","number":"Numbers: 0","value":"rr"},{"cost":"0.00","id":57,"servise":"CliQQ","serviseImg":"bg-fe","number":"Numbers: 0","value":"fe"},{"cost":"0.00","id":58,"servise":"ssoidnet","serviseImg":"bg-la","number":"Numbers: 0","value":"la"},{"cost":"0.00","id":59,"servise":"Zoho","serviseImg":"bg-zh","number":"Numbers: 0","value":"zh"},{"cost":"0.00","id":60,"servise":"Ticketmaster","serviseImg":"bg-gp","number":"Numbers: 0","value":"gp"},{"cost":"0.05","id":61,"servise":"Amazon","serviseImg":"bg-am","number":"Numbers: 25313","value":"am"},{"cost":"0.00","id":62,"servise":"Olacabs","serviseImg":"bg-ly","number":"Numbers: 0","value":"ly"},{"cost":"0.00","id":63,"servise":"Rambler","serviseImg":"bg-tc","number":"Numbers: 0","value":"tc"},{"cost":"0.02","id":64,"servise":"ProtonMail","serviseImg":"bg-dp","number":"Numbers: 30668","value":"dp"},{"cost":"0.00","id":65,"servise":"NRJ Music Awards","serviseImg":"bg-pg","number":"Numbers: 0","value":"pg"},{"cost":"0.03","id":66,"servise":"Citymobil","serviseImg":"bg-yf","number":"Numbers: 26997","value":"yf"},{"cost":"0.00","id":67,"servise":"MIRATORG","serviseImg":"bg-op","number":"Numbers: 0","value":"op"},{"cost":"0.03","id":68,"servise":"PGbonus","serviseImg":"bg-fx","number":"Numbers: 27563","value":"fx"},{"cost":"0.03","id":69,"servise":"MEGA","serviseImg":"bg-qr","number":"Numbers: 27848","value":"qr"},{"cost":"0.03","id":70,"servise":"SportMaster","serviseImg":"bg-yk","number":"Numbers: 26584","value":"yk"},{"cost":"0.03","id":71,"servise":"Careem","serviseImg":"bg-ls","number":"Numbers: 27873","value":"ls"},{"cost":"0.03","id":72,"servise":"BIGO LIVE","serviseImg":"bg-bl","number":"Numbers: 25421","value":"bl"},{"cost":"0.03","id":73,"servise":"MyMusicTaste","serviseImg":"bg-mu","number":"Numbers: 27898","value":"mu"},{"cost":"0.03","id":74,"servise":"Snapchat","serviseImg":"bg-fu","number":"Numbers: 27758","value":"fu"},{"cost":"0.00","id":75,"servise":"Keybase","serviseImg":"bg-bf","number":"Numbers: 0","value":"bf"},{"cost":"0.03","id":76,"servise":"OZON","serviseImg":"bg-sg","number":"Numbers: 26595","value":"sg"},{"cost":"0.03","id":77,"servise":"Wildberries","serviseImg":"bg-uu","number":"Numbers: 27220","value":"uu"},{"cost":"0.05","id":78,"servise":"BlaBlaCar","serviseImg":"bg-ua","number":"Numbers: 24367","value":"ua"},{"cost":"0.09","id":79,"servise":"Alibaba","serviseImg":"bg-ab","number":"Numbers: 17818","value":"ab"},{"cost":"0.00","id":80,"servise":"Inboxlv","serviseImg":"bg-iv","number":"Numbers: 0","value":"iv"},{"cost":"0.00","id":81,"servise":"Nttgame","serviseImg":"bg-zy","number":"Numbers: 0","value":"zy"},{"cost":"0.00","id":82,"servise":"Surveytime","serviseImg":"bg-gd","number":"Numbers: 0","value":"gd"},{"cost":"0.00","id":83,"servise":"Mylove","serviseImg":"bg-fy","number":"Numbers: 0","value":"fy"},{"cost":"0.02","id":84,"servise":"mosru","serviseImg":"bg-ce","number":"Numbers: 27173","value":"ce"},{"cost":"0.00","id":85,"servise":"Truecaller","serviseImg":"bg-tl","number":"Numbers: 0","value":"tl"},{"cost":"0.00","id":86,"servise":"Globus","serviseImg":"bg-hm","number":"Numbers: 0","value":"hm"},{"cost":"0.03","id":87,"servise":"Bolt","serviseImg":"bg-tx","number":"Numbers: 27378","value":"tx"},{"cost":"0.00","id":88,"servise":"Shopee","serviseImg":"bg-ka","number":"Numbers: 0","value":"ka"},{"cost":"0.03","id":89,"servise":"Perekrestok.ru","serviseImg":"bg-pl","number":"Numbers: 27883","value":"pl"},{"cost":"0.03","id":90,"servise":"Burger King","serviseImg":"bg-ip","number":"Numbers: 27764","value":"ip"},{"cost":"0.00","id":91,"servise":"Prom","serviseImg":"bg-cm","number":"Numbers: 0","value":"cm"},{"cost":"0.03","id":92,"servise":"AliPay","serviseImg":"bg-hw","number":"Numbers: 27166","value":"hw"},{"cost":"0.00","id":93,"servise":"Karusel","serviseImg":"bg-de","number":"Numbers: 0","value":"de"},{"cost":"0.00","id":94,"servise":"IVI","serviseImg":"bg-jc","number":"Numbers: 0","value":"jc"},{"cost":"0.03","id":95,"servise":"inDriver","serviseImg":"bg-rl","number":"Numbers: 27534","value":"rl"},{"cost":"0.03","id":96,"servise":"Happn","serviseImg":"bg-df","number":"Numbers: 27785","value":"df"},{"cost":"0.00","id":97,"servise":"RuTube","serviseImg":"bg-ui","number":"Numbers: 0","value":"ui"},{"cost":"0.03","id":98,"servise":"Magnolia","serviseImg":"bg-up","number":"Numbers: 27884","value":"up"},{"cost":"0.03","id":99,"servise":"Foodpanda","serviseImg":"bg-nz","number":"Numbers: 27493","value":"nz"},{"cost":"0.00","id":100,"servise":"Weibo","serviseImg":"bg-kf","number":"Numbers: 0","value":"kf"},{"cost":"0.00","id":101,"servise":"BillMill","serviseImg":"bg-ri","number":"Numbers: 0","value":"ri"},{"cost":"0.00","id":102,"servise":"Quipp","serviseImg":"bg-cc","number":"Numbers: 0","value":"cc"},{"cost":"0.00","id":103,"servise":"Okta","serviseImg":"bg-lr","number":"Numbers: 0","value":"lr"},{"cost":"0.03","id":104,"servise":"JDcom","serviseImg":"bg-za","number":"Numbers: 27891","value":"za"},{"cost":"0.05","id":105,"servise":"MTS CashBack","serviseImg":"bg-da","number":"Numbers: 12860","value":"da"},{"cost":"0.00","id":106,"servise":"Fiqsy","serviseImg":"bg-ug","number":"Numbers: 0","value":"ug"},{"cost":"0.00","id":107,"servise":"KuCoinPlay","serviseImg":"bg-sq","number":"Numbers: 0","value":"sq"},{"cost":"0.00","id":108,"servise":"Papara","serviseImg":"bg-zr","number":"Numbers: 0","value":"zr"},{"cost":"0.00","id":109,"servise":"Wish","serviseImg":"bg-xv","number":"Numbers: 0","value":"xv"},{"cost":"0.00","id":110,"servise":"Icrypex","serviseImg":"bg-cx","number":"Numbers: 0","value":"cx"},{"cost":"0.00","id":111,"servise":"PaddyPower","serviseImg":"bg-cw","number":"Numbers: 0","value":"cw"},{"cost":"0.05","id":112,"servise":"Baidu","serviseImg":"bg-li","number":"Numbers: 27813","value":"li"},{"cost":"0.00","id":113,"servise":"Dominos Pizza","serviseImg":"bg-dz","number":"Numbers: 0","value":"dz"},{"cost":"0.00","id":114,"servise":"paycell","serviseImg":"bg-xz","number":"Numbers: 0","value":"xz"},{"cost":"0.03","id":115,"servise":"Lenta","serviseImg":"bg-rd","number":"Numbers: 27651","value":"rd"},{"cost":"0.00","id":116,"servise":"Payberry","serviseImg":"bg-qb","number":"Numbers: 0","value":"qb"},{"cost":"0.03","id":117,"servise":"Drom","serviseImg":"bg-hz","number":"Numbers: 27673","value":"hz"},{"cost":"0.00","id":118,"servise":"GlobalTel","serviseImg":"bg-gl","number":"Numbers: 0","value":"gl"},{"cost":"0.00","id":119,"servise":"Deliveroo","serviseImg":"bg-zk","number":"Numbers: 0","value":"zk"},{"cost":"0.00","id":120,"servise":"Socios","serviseImg":"bg-ia","number":"Numbers: 0","value":"ia"},{"cost":"0.00","id":121,"servise":"Wmaraci","serviseImg":"bg-xl","number":"Numbers: 0","value":"xl"},{"cost":"0.00","id":122,"servise":"Yemeksepeti","serviseImg":"bg-yi","number":"Numbers: 0","value":"yi"},{"cost":"0.00","id":123,"servise":"Nike","serviseImg":"bg-ew","number":"Numbers: 0","value":"ew"},{"cost":"0.02","id":124,"servise":"myGLO","serviseImg":"bg-ae","number":"Numbers: 31671","value":"ae"},{"cost":"0.02","id":125,"servise":"YouStar","serviseImg":"bg-gb","number":"Numbers: 31133","value":"gb"},{"cost":"0.15","id":126,"servise":"\u0420\u0421\u0410","serviseImg":"bg-cy","number":"Numbers: 25178","value":"cy"},{"cost":"0.00","id":127,"servise":"RosaKhutor","serviseImg":"bg-qm","number":"Numbers: 0","value":"qm"},{"cost":"0.00","id":128,"servise":"eBay","serviseImg":"bg-dh","number":"Numbers: 0","value":"dh"},{"cost":"0.00","id":129,"servise":"Pay.kvartplata.ru+","serviseImg":"bg-yb","number":"Numbers: 0","value":"yb"},{"cost":"0.00","id":130,"servise":"GG","serviseImg":"bg-qe","number":"Numbers: 0","value":"qe"},{"cost":"0.03","id":131,"servise":"Grindr","serviseImg":"bg-yw","number":"Numbers: 4841","value":"yw"},{"cost":"0.00","id":132,"servise":"OffGamers","serviseImg":"bg-uz","number":"Numbers: 0","value":"uz"},{"cost":"0.00","id":133,"servise":"Hepsiburadacom","serviseImg":"bg-gx","number":"Numbers: 0","value":"gx"},{"cost":"0.00","id":134,"servise":"Coinbase","serviseImg":"bg-re","number":"Numbers: 0","value":"re"},{"cost":"0.00","id":135,"servise":"RADA NABU","serviseImg":"bg-tj","number":"Numbers: 0","value":"tj"},{"cost":"0.09","id":136,"servise":"PayPal","serviseImg":"bg-ts","number":"Numbers: 27144","value":"ts"},{"cost":"0.00","id":137,"servise":"hily","serviseImg":"bg-rt","number":"Numbers: 0","value":"rt"},{"cost":"0.00","id":138,"servise":"SneakersnStuff","serviseImg":"bg-sf","number":"Numbers: 0","value":"sf"},{"cost":"0.00","id":139,"servise":"Dostavista","serviseImg":"bg-sv","number":"Numbers: 0","value":"sv"},{"cost":"0.00","id":140,"servise":"32red","serviseImg":"bg-qi","number":"Numbers: 0","value":"qi"},{"cost":"0.02","id":141,"servise":"Blizzard","serviseImg":"bg-bz","number":"Numbers: 27797","value":"bz"},{"cost":"0.00","id":142,"servise":"ezbuy","serviseImg":"bg-db","number":"Numbers: 0","value":"db"},{"cost":"0.00","id":143,"servise":"CoinField","serviseImg":"bg-vw","number":"Numbers: 0","value":"vw"},{"cost":"0.00","id":144,"servise":"Airtel","serviseImg":"bg-zl","number":"Numbers: 0","value":"zl"},{"cost":"0.00","id":145,"servise":"Airtel","serviseImg":"bg-wf","number":"Numbers: 0","value":"wf"},{"cost":"0.00","id":146,"servise":"MrGreen","serviseImg":"bg-lw","number":"Numbers: 0","value":"lw"},{"cost":"0.00","id":147,"servise":"Rediffmail","serviseImg":"bg-co","number":"Numbers: 0","value":"co"},{"cost":"0.00","id":148,"servise":"miloan","serviseImg":"bg-ey","number":"Numbers: 0","value":"ey"},{"cost":"0.00","id":149,"servise":"Paytm","serviseImg":"bg-ge","number":"Numbers: 0","value":"ge"},{"cost":"0.00","id":150,"servise":"Dhani","serviseImg":"bg-os","number":"Numbers: 0","value":"os"},{"cost":"0.00","id":151,"servise":"CMTcuzdan","serviseImg":"bg-ql","number":"Numbers: 0","value":"ql"},{"cost":"0.00","id":152,"servise":"Mercado","serviseImg":"bg-cq","number":"Numbers: 0","value":"cq"},{"cost":"0.05","id":153,"servise":"DiDi","serviseImg":"bg-xk","number":"Numbers: 26447","value":"xk"},{"cost":"0.00","id":154,"servise":"Monese","serviseImg":"bg-py","number":"Numbers: 0","value":"py"},{"cost":"0.00","id":155,"servise":"Kotak811","serviseImg":"bg-rv","number":"Numbers: 0","value":"rv"},{"cost":"0.00","id":156,"servise":"Hopi","serviseImg":"bg-jl","number":"Numbers: 0","value":"jl"},{"cost":"0.00","id":157,"servise":"Trendyol","serviseImg":"bg-pr","number":"Numbers: 0","value":"pr"},{"cost":"0.00","id":158,"servise":"Justdating","serviseImg":"bg-pu","number":"Numbers: 0","value":"pu"},{"cost":"0.00","id":159,"servise":"Pairs","serviseImg":"bg-dk","number":"Numbers: 0","value":"dk"},{"cost":"0.00","id":160,"servise":"Touchance","serviseImg":"bg-fm","number":"Numbers: 0","value":"fm"},{"cost":"0.00","id":161,"servise":"SnappFood","serviseImg":"bg-ph","number":"Numbers: 0","value":"ph"},{"cost":"0.00","id":162,"servise":"NCsoft","serviseImg":"bg-sw","number":"Numbers: 0","value":"sw"},{"cost":"0.00","id":163,"servise":"Tosla","serviseImg":"bg-nr","number":"Numbers: 0","value":"nr"},{"cost":"0.00","id":164,"servise":"Ininal","serviseImg":"bg-hy","number":"Numbers: 0","value":"hy"},{"cost":"0.00","id":165,"servise":"Paysend","serviseImg":"bg-tr","number":"Numbers: 0","value":"tr"},{"cost":"0.00","id":166,"servise":"CDkeys","serviseImg":"bg-pq","number":"Numbers: 0","value":"pq"},{"cost":"0.00","id":167,"servise":"AVON","serviseImg":"bg-ff","number":"Numbers: 0","value":"ff"},{"cost":"0.03","id":168,"servise":"dodopizza","serviseImg":"bg-sd","number":"Numbers: 27739","value":"sd"},{"cost":"0.24","id":169,"servise":"McDonalds","serviseImg":"bg-ry","number":"Numbers: 7729","value":"ry"},{"cost":"0.00","id":170,"servise":"E bike Gewinnspiel","serviseImg":"bg-le","number":"Numbers: 0","value":"le"},{"cost":"0.00","id":171,"servise":"JKF","serviseImg":"bg-hr","number":"Numbers: 0","value":"hr"},{"cost":"0.00","id":172,"servise":"MyFishka","serviseImg":"bg-qa","number":"Numbers: 0","value":"qa"},{"cost":"0.00","id":173,"servise":"Craigslist","serviseImg":"bg-wc","number":"Numbers: 0","value":"wc"},{"cost":"0.00","id":174,"servise":"Foody","serviseImg":"bg-kw","number":"Numbers: 0","value":"kw"},{"cost":"0.00","id":175,"servise":"Grab","serviseImg":"bg-jg","number":"Numbers: 0","value":"jg"},{"cost":"0.05","id":176,"servise":"Zalo","serviseImg":"bg-mj","number":"Numbers: 28606","value":"mj"},{"cost":"0.00","id":177,"servise":"LiveScore","serviseImg":"bg-eu","number":"Numbers: 0","value":"eu"},{"cost":"0.00","id":178,"servise":"888casino","serviseImg":"bg-ll","number":"Numbers: 0","value":"ll"},{"cost":"0.00","id":179,"servise":"Gamer","serviseImg":"bg-ed","number":"Numbers: 0","value":"ed"},{"cost":"0.00","id":180,"servise":"Huya","serviseImg":"bg-pp","number":"Numbers: 0","value":"pp"},{"cost":"0.00","id":181,"servise":"WestStein","serviseImg":"bg-th","number":"Numbers: 0","value":"th"},{"cost":"0.04","id":182,"servise":"Tango","serviseImg":"bg-xr","number":"Numbers: 27765","value":"xr"},{"cost":"0.00","id":183,"servise":"Global24","serviseImg":"bg-iz","number":"Numbers: 0","value":"iz"},{"cost":"0.03","id":184,"servise":"\u041c\u0412\u0438\u0434\u0435\u043e","serviseImg":"bg-tk","number":"Numbers: 27660","value":"tk"},{"cost":"0.00","id":185,"servise":"Sheerid","serviseImg":"bg-rx","number":"Numbers: 0","value":"rx"},{"cost":"0.00","id":186,"servise":"99app","serviseImg":"bg-ki","number":"Numbers: 0","value":"ki"},{"cost":"0.00","id":187,"servise":"CAIXA","serviseImg":"bg-my","number":"Numbers: 0","value":"my"},{"cost":"0.00","id":188,"servise":"OfferUp","serviseImg":"bg-zm","number":"Numbers: 0","value":"zm"},{"cost":"0.00","id":189,"servise":"Swvl","serviseImg":"bg-tq","number":"Numbers: 0","value":"tq"},{"cost":"0.00","id":190,"servise":"Haraj","serviseImg":"bg-au","number":"Numbers: 0","value":"au"},{"cost":"0.00","id":191,"servise":"Taksheel","serviseImg":"bg-ei","number":"Numbers: 0","value":"ei"},{"cost":"0.00","id":192,"servise":"hamrahaval","serviseImg":"bg-rp","number":"Numbers: 0","value":"rp"},{"cost":"0.00","id":193,"servise":"Gamekit","serviseImg":"bg-pa","number":"Numbers: 0","value":"pa"},{"cost":"0.00","id":194,"servise":" \u015eikayet var","serviseImg":"bg-fs","number":"Numbers: 0","value":"fs"},{"cost":"0.00","id":195,"servise":"Getir","serviseImg":"bg-ul","number":"Numbers: 0","value":"ul"},{"cost":"0.00","id":196,"servise":"irancell","serviseImg":"bg-cf","number":"Numbers: 0","value":"cf"},{"cost":"0.00","id":197,"servise":"Alfa","serviseImg":"bg-bt","number":"Numbers: 0","value":"bt"},{"cost":"0.00","id":198,"servise":"Disney Hotstar","serviseImg":"bg-ud","number":"Numbers: 0","value":"ud"},{"cost":"0.00","id":199,"servise":"Agroinform","serviseImg":"bg-qu","number":"Numbers: 0","value":"qu"},{"cost":"0.00","id":200,"servise":"humblebundle","serviseImg":"bg-un","number":"Numbers: 0","value":"un"},{"cost":"0.00","id":201,"servise":"Faberlic","serviseImg":"bg-rm","number":"Numbers: 0","value":"rm"},{"cost":"0.00","id":202,"servise":"CafeBazaar","serviseImg":"bg-uo","number":"Numbers: 0","value":"uo"},{"cost":"0.00","id":203,"servise":"cryptocom","serviseImg":"bg-ti","number":"Numbers: 0","value":"ti"},{"cost":"0.00","id":204,"servise":"Gittigidiyor","serviseImg":"bg-nk","number":"Numbers: 0","value":"nk"},{"cost":"0.00","id":205,"servise":"mzadqatar","serviseImg":"bg-jm","number":"Numbers: 0","value":"jm"},{"cost":"0.00","id":206,"servise":"Algida","serviseImg":"bg-lp","number":"Numbers: 0","value":"lp"},{"cost":"0.00","id":207,"servise":"Cita Previa","serviseImg":"bg-si","number":"Numbers: 0","value":"si"},{"cost":"0.00","id":208,"servise":"Potato Chat","serviseImg":"bg-fj","number":"Numbers: 0","value":"fj"},{"cost":"0.00","id":209,"servise":"Bitaqaty","serviseImg":"bg-pt","number":"Numbers: 0","value":"pt"},{"cost":"0.00","id":210,"servise":"Primaries 2020","serviseImg":"bg-qc","number":"Numbers: 0","value":"qc"},{"cost":"0.00","id":211,"servise":"Amasia","serviseImg":"bg-yo","number":"Numbers: 0","value":"yo"},{"cost":"0.00","id":212,"servise":"Dream11","serviseImg":"bg-ve","number":"Numbers: 0","value":"ve"},{"cost":"0.00","id":213,"servise":"Oriflame","serviseImg":"bg-qh","number":"Numbers: 0","value":"qh"},{"cost":"0.00","id":214,"servise":"Bykea","serviseImg":"bg-iu","number":"Numbers: 0","value":"iu"},{"cost":"0.00","id":215,"servise":"Immowelt","serviseImg":"bg-ib","number":"Numbers: 0","value":"ib"},{"cost":"0.00","id":216,"servise":"Digikala","serviseImg":"bg-zv","number":"Numbers: 0","value":"zv"},{"cost":"0.00","id":217,"servise":"Wing Money","serviseImg":"bg-jb","number":"Numbers: 0","value":"jb"},{"cost":"0.00","id":218,"servise":"Yaay","serviseImg":"bg-vn","number":"Numbers: 0","value":"vn"},{"cost":"0.00","id":219,"servise":"GameArena","serviseImg":"bg-wn","number":"Numbers: 0","value":"wn"},{"cost":"0.04","id":220,"servise":"Vita express","serviseImg":"bg-bj","number":"Numbers: 27861","value":"bj"},{"cost":"0.00","id":221,"servise":"Auchan","serviseImg":"bg-st","number":"Numbers: 0","value":"st"},{"cost":"0.00","id":222,"servise":"Picpay","serviseImg":"bg-ev","number":"Numbers: 0","value":"ev"},{"cost":"0.00","id":223,"servise":"Blued","serviseImg":"bg-qn","number":"Numbers: 0","value":"qn"},{"cost":"0.05","id":224,"servise":"Not on the list","serviseImg":"bg-ot","number":"Numbers: 19352","value":"ot"}]
The problem is that after my knowledge this is a wrong formatted json file, even if I remove "[" and "]".
I though of just looking at it as a text file to get a specific value but I was unable to find something on the internet about this topic.
I want to get the following value:
From:
{"cost":"0.00","id":123,"servise":"Nike","serviseImg":"bg-ew","number":"Numbers: 0","value":"ew"}
I want to get:
Numbers: 0
Use json.loads to become a dictionary query:
import requests
import json
response = requests.get('https://sms-service-online.com/api/getServicesAndCost/?country=0&operator=any&lang=en')
data = response.json()
plain = data["data"]
for d in json.loads(plain):
if d['id'] == 123:
print(d)
You have a list of dict in your first example. So first you need to select which dict you want. For instance, if your query is called 'json_list'
json_list[2]
will get you the third item in that list.
For what you are asking, try:
j = {"cost":"0.00","id":123,"servise":"Nike","serviseImg":"bg-ew","number":"Numbers: 0","value":"ew"}
j["number"].split()[-1]
Assuming you want to check all numbers in all dict, try:
json_list=[{"cost":"0.45","id":0,"servise":"VK.com","serviseImg":"bg-vk","number":"Numbers: 3047","value":"vk"},{"cost":"0.07","id":1,"servise":"OK.ru","serviseImg":"bg-ok","number":"Numbers: 14397","value":"ok"},{"cost":"0.15","id":2,"servise":"Whatsapp","serviseImg":"bg-wa","number":"Numbers: 17610","value":"wa"},{"cost":"0.18","id":3,"servise":"Viber","serviseImg":"bg-vi","number":"Numbers: 413","value":"vi"},{"cost":"0.00","id":4,"servise":"Telegram","serviseImg":"bg-tg","number":"Numbers: 0","value":"tg"},{"cost":"0.30","id":5,"servise":"WeChat","serviseImg":"bg-wb","number":"Numbers: 28389","value":"wb"},{"cost":"0.15","id":6,"servise":"Google,youtube,Gmail","serviseImg":"bg-go","number":"Numbers: 15419","value":"go"},{"cost":"0.11","id":7,"servise":"avito","serviseImg":"bg-av","number":"Numbers: 17379","value":"av"},{"cost":"0.07","id":8,"servise":"facebook","serviseImg":"bg-fb","number":"Numbers: 21636","value":"fb"},{"cost":"0.03","id":9,"servise":"Twitter","serviseImg":"bg-tw","number":"Numbers: 26864","value":"tw"},{"cost":"0.05","id":10,"servise":"Uber","serviseImg":"bg-ub","number":"Numbers: 20975","value":"ub"},{"cost":"0.22","id":11,"servise":"Qiwi","serviseImg":"bg-qw","number":"Numbers: 20371","value":"qw"},{"cost":"0.02","id":12,"servise":"Gett","serviseImg":"bg-gt","number":"Numbers: 28501","value":"gt"},{"cost":"0.00","id":13,"servise":"OLX","serviseImg":"bg-sn","number":"Numbers: 0","value":"sn"},{"cost":"0.14","id":14,"servise":"Instagram","serviseImg":"bg-ig","number":"Numbers: 3799","value":"ig"},{"cost":"0.00","id":15,"servise":"Hezzl","serviseImg":"bg-ss","number":"Numbers: 0","value":"ss"},{"cost":"0.07","id":16,"servise":"\u042e\u043b\u0430","serviseImg":"bg-ym","number":"Numbers: 17597","value":"ym"},{"cost":"0.03","id":17,"servise":"Mail.ru","serviseImg":"bg-ma","number":"Numbers: 17936","value":"ma"},{"cost":"0.03","id":18,"servise":"Microsoft","serviseImg":"bg-mm","number":"Numbers: 3830","value":"mm"},{"cost":"0.03","id":19,"servise":"Airbnb","serviseImg":"bg-uk","number":"Numbers: 28266","value":"uk"},{"cost":"0.00","id":20,"servise":"Line messenger","serviseImg":"bg-me","number":"Numbers: 0","value":"me"},{"cost":"0.03","id":21,"servise":"Yahoo","serviseImg":"bg-mb","number":"Numbers: 19077","value":"mb"},{"cost":"0.00","id":22,"servise":"Drugvokrug.ru","serviseImg":"bg-we","number":"Numbers: 0","value":"we"},{"cost":"0.05","id":23,"servise":"5ka.ru","serviseImg":"bg-bd","number":"Numbers: 27541","value":"bd"},{"cost":"0.00","id":24,"servise":"HQ Trivia","serviseImg":"bg-kp","number":"Numbers: 0","value":"kp"},{"cost":"0.65","id":25,"servise":"Delivery Club","serviseImg":"bg-dt","number":"Numbers: 26812","value":"dt"},{"cost":"0.03","id":26,"servise":"Yandex","serviseImg":"bg-ya","number":"Numbers: 20944","value":"ya"},{"cost":"0.05","id":27,"servise":"Steam","serviseImg":"bg-mt","number":"Numbers: 28121","value":"mt"},{"cost":"0.04","id":28,"servise":"Tinder","serviseImg":"bg-oi","number":"Numbers: 27478","value":"oi"},{"cost":"0.02","id":29,"servise":"Mamba, MeetMe","serviseImg":"bg-fd","number":"Numbers: 25328","value":"fd"},{"cost":"0.00","id":30,"servise":"Dent","serviseImg":"bg-zz","number":"Numbers: 0","value":"zz"},{"cost":"0.07","id":31,"servise":"KakaoTalk","serviseImg":"bg-kt","number":"Numbers: 27823","value":"kt"},{"cost":"0.04","id":32,"servise":"AOL","serviseImg":"bg-pm","number":"Numbers: 23369","value":"pm"},{"cost":"0.02","id":33,"servise":"LinkedIN","serviseImg":"bg-tn","number":"Numbers: 32192","value":"tn"},{"cost":"0.03","id":34,"servise":"Tencent QQ","serviseImg":"bg-qq","number":"Numbers: 27883","value":"qq"},{"cost":"0.06","id":35,"servise":"Magnit","serviseImg":"bg-mg","number":"Numbers: 993","value":"mg"},{"cost":"0.00","id":36,"servise":"pof.com","serviseImg":"bg-pf","number":"Numbers: 0","value":"pf"},{"cost":"0.03","id":37,"servise":"Yalla","serviseImg":"bg-yl","number":"Numbers: 27822","value":"yl"},{"cost":"0.00","id":38,"servise":"kolesa.kz","serviseImg":"bg-kl","number":"Numbers: 0","value":"kl"},{"cost":"0.03","id":39,"servise":"premium.one","serviseImg":"bg-po","number":"Numbers: 25869","value":"po"},{"cost":"0.07","id":40,"servise":"Naver","serviseImg":"bg-nv","number":"Numbers: 27582","value":"nv"},{"cost":"0.03","id":41,"servise":"Netflix","serviseImg":"bg-nf","number":"Numbers: 27715","value":"nf"},{"cost":"0.00","id":42,"servise":"icq","serviseImg":"bg-iq","number":"Numbers: 0","value":"iq"},{"cost":"0.00","id":43,"servise":"Onlinerby","serviseImg":"bg-ob","number":"Numbers: 0","value":"ob"},{"cost":"0.00","id":44,"servise":"kufarby","serviseImg":"bg-kb","number":"Numbers: 0","value":"kb"},{"cost":"0.03","id":45,"servise":"Imo","serviseImg":"bg-im","number":"Numbers: 25198","value":"im"},{"cost":"0.00","id":46,"servise":"Michat","serviseImg":"bg-mc","number":"Numbers: 0","value":"mc"},{"cost":"0.03","id":47,"servise":"Discord","serviseImg":"bg-ds","number":"Numbers: 22011","value":"ds"},{"cost":"0.00","id":48,"servise":"Seosprint","serviseImg":"bg-vv","number":"Numbers: 0","value":"vv"},{"cost":"0.00","id":49,"servise":"Monobank","serviseImg":"bg-ji","number":"Numbers: 0","value":"ji"},{"cost":"0.03","id":50,"servise":"TikTok\/Douyin","serviseImg":"bg-lf","number":"Numbers: 26299","value":"lf"},{"cost":"0.00","id":51,"servise":"Ukrnet","serviseImg":"bg-hu","number":"Numbers: 0","value":"hu"},{"cost":"0.00","id":52,"servise":"Skout","serviseImg":"bg-wg","number":"Numbers: 0","value":"wg"},{"cost":"0.00","id":53,"servise":"EasyPay","serviseImg":"bg-rz","number":"Numbers: 0","value":"rz"},{"cost":"0.00","id":54,"servise":"Q12 Trivia","serviseImg":"bg-vf","number":"Numbers: 0","value":"vf"},{"cost":"0.00","id":55,"servise":"Pyro Music","serviseImg":"bg-ny","number":"Numbers: 0","value":"ny"},{"cost":"0.00","id":56,"servise":"Wolt","serviseImg":"bg-rr","number":"Numbers: 0","value":"rr"},{"cost":"0.00","id":57,"servise":"CliQQ","serviseImg":"bg-fe","number":"Numbers: 0","value":"fe"},{"cost":"0.00","id":58,"servise":"ssoidnet","serviseImg":"bg-la","number":"Numbers: 0","value":"la"},{"cost":"0.00","id":59,"servise":"Zoho","serviseImg":"bg-zh","number":"Numbers: 0","value":"zh"},{"cost":"0.00","id":60,"servise":"Ticketmaster","serviseImg":"bg-gp","number":"Numbers: 0","value":"gp"},{"cost":"0.05","id":61,"servise":"Amazon","serviseImg":"bg-am","number":"Numbers: 25313","value":"am"},{"cost":"0.00","id":62,"servise":"Olacabs","serviseImg":"bg-ly","number":"Numbers: 0","value":"ly"},{"cost":"0.00","id":63,"servise":"Rambler","serviseImg":"bg-tc","number":"Numbers: 0","value":"tc"},{"cost":"0.02","id":64,"servise":"ProtonMail","serviseImg":"bg-dp","number":"Numbers: 30668","value":"dp"},{"cost":"0.00","id":65,"servise":"NRJ Music Awards","serviseImg":"bg-pg","number":"Numbers: 0","value":"pg"},{"cost":"0.03","id":66,"servise":"Citymobil","serviseImg":"bg-yf","number":"Numbers: 26997","value":"yf"},{"cost":"0.00","id":67,"servise":"MIRATORG","serviseImg":"bg-op","number":"Numbers: 0","value":"op"},{"cost":"0.03","id":68,"servise":"PGbonus","serviseImg":"bg-fx","number":"Numbers: 27563","value":"fx"},{"cost":"0.03","id":69,"servise":"MEGA","serviseImg":"bg-qr","number":"Numbers: 27848","value":"qr"},{"cost":"0.03","id":70,"servise":"SportMaster","serviseImg":"bg-yk","number":"Numbers: 26584","value":"yk"},{"cost":"0.03","id":71,"servise":"Careem","serviseImg":"bg-ls","number":"Numbers: 27873","value":"ls"},{"cost":"0.03","id":72,"servise":"BIGO LIVE","serviseImg":"bg-bl","number":"Numbers: 25421","value":"bl"},{"cost":"0.03","id":73,"servise":"MyMusicTaste","serviseImg":"bg-mu","number":"Numbers: 27898","value":"mu"},{"cost":"0.03","id":74,"servise":"Snapchat","serviseImg":"bg-fu","number":"Numbers: 27758","value":"fu"},{"cost":"0.00","id":75,"servise":"Keybase","serviseImg":"bg-bf","number":"Numbers: 0","value":"bf"},{"cost":"0.03","id":76,"servise":"OZON","serviseImg":"bg-sg","number":"Numbers: 26595","value":"sg"},{"cost":"0.03","id":77,"servise":"Wildberries","serviseImg":"bg-uu","number":"Numbers: 27220","value":"uu"},{"cost":"0.05","id":78,"servise":"BlaBlaCar","serviseImg":"bg-ua","number":"Numbers: 24367","value":"ua"},{"cost":"0.09","id":79,"servise":"Alibaba","serviseImg":"bg-ab","number":"Numbers: 17818","value":"ab"},{"cost":"0.00","id":80,"servise":"Inboxlv","serviseImg":"bg-iv","number":"Numbers: 0","value":"iv"},{"cost":"0.00","id":81,"servise":"Nttgame","serviseImg":"bg-zy","number":"Numbers: 0","value":"zy"},{"cost":"0.00","id":82,"servise":"Surveytime","serviseImg":"bg-gd","number":"Numbers: 0","value":"gd"},{"cost":"0.00","id":83,"servise":"Mylove","serviseImg":"bg-fy","number":"Numbers: 0","value":"fy"},{"cost":"0.02","id":84,"servise":"mosru","serviseImg":"bg-ce","number":"Numbers: 27173","value":"ce"},{"cost":"0.00","id":85,"servise":"Truecaller","serviseImg":"bg-tl","number":"Numbers: 0","value":"tl"},{"cost":"0.00","id":86,"servise":"Globus","serviseImg":"bg-hm","number":"Numbers: 0","value":"hm"},{"cost":"0.03","id":87,"servise":"Bolt","serviseImg":"bg-tx","number":"Numbers: 27378","value":"tx"},{"cost":"0.00","id":88,"servise":"Shopee","serviseImg":"bg-ka","number":"Numbers: 0","value":"ka"},{"cost":"0.03","id":89,"servise":"Perekrestok.ru","serviseImg":"bg-pl","number":"Numbers: 27883","value":"pl"},{"cost":"0.03","id":90,"servise":"Burger King","serviseImg":"bg-ip","number":"Numbers: 27764","value":"ip"},{"cost":"0.00","id":91,"servise":"Prom","serviseImg":"bg-cm","number":"Numbers: 0","value":"cm"},{"cost":"0.03","id":92,"servise":"AliPay","serviseImg":"bg-hw","number":"Numbers: 27166","value":"hw"},{"cost":"0.00","id":93,"servise":"Karusel","serviseImg":"bg-de","number":"Numbers: 0","value":"de"},{"cost":"0.00","id":94,"servise":"IVI","serviseImg":"bg-jc","number":"Numbers: 0","value":"jc"},{"cost":"0.03","id":95,"servise":"inDriver","serviseImg":"bg-rl","number":"Numbers: 27534","value":"rl"},{"cost":"0.03","id":96,"servise":"Happn","serviseImg":"bg-df","number":"Numbers: 27785","value":"df"},{"cost":"0.00","id":97,"servise":"RuTube","serviseImg":"bg-ui","number":"Numbers: 0","value":"ui"},{"cost":"0.03","id":98,"servise":"Magnolia","serviseImg":"bg-up","number":"Numbers: 27884","value":"up"},{"cost":"0.03","id":99,"servise":"Foodpanda","serviseImg":"bg-nz","number":"Numbers: 27493","value":"nz"},{"cost":"0.00","id":100,"servise":"Weibo","serviseImg":"bg-kf","number":"Numbers: 0","value":"kf"},{"cost":"0.00","id":101,"servise":"BillMill","serviseImg":"bg-ri","number":"Numbers: 0","value":"ri"},{"cost":"0.00","id":102,"servise":"Quipp","serviseImg":"bg-cc","number":"Numbers: 0","value":"cc"},{"cost":"0.00","id":103,"servise":"Okta","serviseImg":"bg-lr","number":"Numbers: 0","value":"lr"},{"cost":"0.03","id":104,"servise":"JDcom","serviseImg":"bg-za","number":"Numbers: 27891","value":"za"},{"cost":"0.05","id":105,"servise":"MTS CashBack","serviseImg":"bg-da","number":"Numbers: 12860","value":"da"},{"cost":"0.00","id":106,"servise":"Fiqsy","serviseImg":"bg-ug","number":"Numbers: 0","value":"ug"},{"cost":"0.00","id":107,"servise":"KuCoinPlay","serviseImg":"bg-sq","number":"Numbers: 0","value":"sq"},{"cost":"0.00","id":108,"servise":"Papara","serviseImg":"bg-zr","number":"Numbers: 0","value":"zr"},{"cost":"0.00","id":109,"servise":"Wish","serviseImg":"bg-xv","number":"Numbers: 0","value":"xv"},{"cost":"0.00","id":110,"servise":"Icrypex","serviseImg":"bg-cx","number":"Numbers: 0","value":"cx"},{"cost":"0.00","id":111,"servise":"PaddyPower","serviseImg":"bg-cw","number":"Numbers: 0","value":"cw"},{"cost":"0.05","id":112,"servise":"Baidu","serviseImg":"bg-li","number":"Numbers: 27813","value":"li"},{"cost":"0.00","id":113,"servise":"Dominos Pizza","serviseImg":"bg-dz","number":"Numbers: 0","value":"dz"},{"cost":"0.00","id":114,"servise":"paycell","serviseImg":"bg-xz","number":"Numbers: 0","value":"xz"},{"cost":"0.03","id":115,"servise":"Lenta","serviseImg":"bg-rd","number":"Numbers: 27651","value":"rd"},{"cost":"0.00","id":116,"servise":"Payberry","serviseImg":"bg-qb","number":"Numbers: 0","value":"qb"},{"cost":"0.03","id":117,"servise":"Drom","serviseImg":"bg-hz","number":"Numbers: 27673","value":"hz"},{"cost":"0.00","id":118,"servise":"GlobalTel","serviseImg":"bg-gl","number":"Numbers: 0","value":"gl"},{"cost":"0.00","id":119,"servise":"Deliveroo","serviseImg":"bg-zk","number":"Numbers: 0","value":"zk"},{"cost":"0.00","id":120,"servise":"Socios","serviseImg":"bg-ia","number":"Numbers: 0","value":"ia"},{"cost":"0.00","id":121,"servise":"Wmaraci","serviseImg":"bg-xl","number":"Numbers: 0","value":"xl"},{"cost":"0.00","id":122,"servise":"Yemeksepeti","serviseImg":"bg-yi","number":"Numbers: 0","value":"yi"},{"cost":"0.00","id":123,"servise":"Nike","serviseImg":"bg-ew","number":"Numbers: 0","value":"ew"},{"cost":"0.02","id":124,"servise":"myGLO","serviseImg":"bg-ae","number":"Numbers: 31671","value":"ae"},{"cost":"0.02","id":125,"servise":"YouStar","serviseImg":"bg-gb","number":"Numbers: 31133","value":"gb"},{"cost":"0.15","id":126,"servise":"\u0420\u0421\u0410","serviseImg":"bg-cy","number":"Numbers: 25178","value":"cy"},{"cost":"0.00","id":127,"servise":"RosaKhutor","serviseImg":"bg-qm","number":"Numbers: 0","value":"qm"},{"cost":"0.00","id":128,"servise":"eBay","serviseImg":"bg-dh","number":"Numbers: 0","value":"dh"},{"cost":"0.00","id":129,"servise":"Pay.kvartplata.ru+","serviseImg":"bg-yb","number":"Numbers: 0","value":"yb"},{"cost":"0.00","id":130,"servise":"GG","serviseImg":"bg-qe","number":"Numbers: 0","value":"qe"},{"cost":"0.03","id":131,"servise":"Grindr","serviseImg":"bg-yw","number":"Numbers: 4841","value":"yw"},{"cost":"0.00","id":132,"servise":"OffGamers","serviseImg":"bg-uz","number":"Numbers: 0","value":"uz"},{"cost":"0.00","id":133,"servise":"Hepsiburadacom","serviseImg":"bg-gx","number":"Numbers: 0","value":"gx"},{"cost":"0.00","id":134,"servise":"Coinbase","serviseImg":"bg-re","number":"Numbers: 0","value":"re"},{"cost":"0.00","id":135,"servise":"RADA NABU","serviseImg":"bg-tj","number":"Numbers: 0","value":"tj"},{"cost":"0.09","id":136,"servise":"PayPal","serviseImg":"bg-ts","number":"Numbers: 27144","value":"ts"},{"cost":"0.00","id":137,"servise":"hily","serviseImg":"bg-rt","number":"Numbers: 0","value":"rt"},{"cost":"0.00","id":138,"servise":"SneakersnStuff","serviseImg":"bg-sf","number":"Numbers: 0","value":"sf"},{"cost":"0.00","id":139,"servise":"Dostavista","serviseImg":"bg-sv","number":"Numbers: 0","value":"sv"},{"cost":"0.00","id":140,"servise":"32red","serviseImg":"bg-qi","number":"Numbers: 0","value":"qi"},{"cost":"0.02","id":141,"servise":"Blizzard","serviseImg":"bg-bz","number":"Numbers: 27797","value":"bz"},{"cost":"0.00","id":142,"servise":"ezbuy","serviseImg":"bg-db","number":"Numbers: 0","value":"db"},{"cost":"0.00","id":143,"servise":"CoinField","serviseImg":"bg-vw","number":"Numbers: 0","value":"vw"},{"cost":"0.00","id":144,"servise":"Airtel","serviseImg":"bg-zl","number":"Numbers: 0","value":"zl"},{"cost":"0.00","id":145,"servise":"Airtel","serviseImg":"bg-wf","number":"Numbers: 0","value":"wf"},{"cost":"0.00","id":146,"servise":"MrGreen","serviseImg":"bg-lw","number":"Numbers: 0","value":"lw"},{"cost":"0.00","id":147,"servise":"Rediffmail","serviseImg":"bg-co","number":"Numbers: 0","value":"co"},{"cost":"0.00","id":148,"servise":"miloan","serviseImg":"bg-ey","number":"Numbers: 0","value":"ey"},{"cost":"0.00","id":149,"servise":"Paytm","serviseImg":"bg-ge","number":"Numbers: 0","value":"ge"},{"cost":"0.00","id":150,"servise":"Dhani","serviseImg":"bg-os","number":"Numbers: 0","value":"os"},{"cost":"0.00","id":151,"servise":"CMTcuzdan","serviseImg":"bg-ql","number":"Numbers: 0","value":"ql"},{"cost":"0.00","id":152,"servise":"Mercado","serviseImg":"bg-cq","number":"Numbers: 0","value":"cq"},{"cost":"0.05","id":153,"servise":"DiDi","serviseImg":"bg-xk","number":"Numbers: 26447","value":"xk"},{"cost":"0.00","id":154,"servise":"Monese","serviseImg":"bg-py","number":"Numbers: 0","value":"py"},{"cost":"0.00","id":155,"servise":"Kotak811","serviseImg":"bg-rv","number":"Numbers: 0","value":"rv"},{"cost":"0.00","id":156,"servise":"Hopi","serviseImg":"bg-jl","number":"Numbers: 0","value":"jl"},{"cost":"0.00","id":157,"servise":"Trendyol","serviseImg":"bg-pr","number":"Numbers: 0","value":"pr"},{"cost":"0.00","id":158,"servise":"Justdating","serviseImg":"bg-pu","number":"Numbers: 0","value":"pu"},{"cost":"0.00","id":159,"servise":"Pairs","serviseImg":"bg-dk","number":"Numbers: 0","value":"dk"},{"cost":"0.00","id":160,"servise":"Touchance","serviseImg":"bg-fm","number":"Numbers: 0","value":"fm"},{"cost":"0.00","id":161,"servise":"SnappFood","serviseImg":"bg-ph","number":"Numbers: 0","value":"ph"},{"cost":"0.00","id":162,"servise":"NCsoft","serviseImg":"bg-sw","number":"Numbers: 0","value":"sw"},{"cost":"0.00","id":163,"servise":"Tosla","serviseImg":"bg-nr","number":"Numbers: 0","value":"nr"},{"cost":"0.00","id":164,"servise":"Ininal","serviseImg":"bg-hy","number":"Numbers: 0","value":"hy"},{"cost":"0.00","id":165,"servise":"Paysend","serviseImg":"bg-tr","number":"Numbers: 0","value":"tr"},{"cost":"0.00","id":166,"servise":"CDkeys","serviseImg":"bg-pq","number":"Numbers: 0","value":"pq"},{"cost":"0.00","id":167,"servise":"AVON","serviseImg":"bg-ff","number":"Numbers: 0","value":"ff"},{"cost":"0.03","id":168,"servise":"dodopizza","serviseImg":"bg-sd","number":"Numbers: 27739","value":"sd"},{"cost":"0.24","id":169,"servise":"McDonalds","serviseImg":"bg-ry","number":"Numbers: 7729","value":"ry"},{"cost":"0.00","id":170,"servise":"E bike Gewinnspiel","serviseImg":"bg-le","number":"Numbers: 0","value":"le"},{"cost":"0.00","id":171,"servise":"JKF","serviseImg":"bg-hr","number":"Numbers: 0","value":"hr"},{"cost":"0.00","id":172,"servise":"MyFishka","serviseImg":"bg-qa","number":"Numbers: 0","value":"qa"},{"cost":"0.00","id":173,"servise":"Craigslist","serviseImg":"bg-wc","number":"Numbers: 0","value":"wc"},{"cost":"0.00","id":174,"servise":"Foody","serviseImg":"bg-kw","number":"Numbers: 0","value":"kw"},{"cost":"0.00","id":175,"servise":"Grab","serviseImg":"bg-jg","number":"Numbers: 0","value":"jg"},{"cost":"0.05","id":176,"servise":"Zalo","serviseImg":"bg-mj","number":"Numbers: 28606","value":"mj"},{"cost":"0.00","id":177,"servise":"LiveScore","serviseImg":"bg-eu","number":"Numbers: 0","value":"eu"},{"cost":"0.00","id":178,"servise":"888casino","serviseImg":"bg-ll","number":"Numbers: 0","value":"ll"},{"cost":"0.00","id":179,"servise":"Gamer","serviseImg":"bg-ed","number":"Numbers: 0","value":"ed"},{"cost":"0.00","id":180,"servise":"Huya","serviseImg":"bg-pp","number":"Numbers: 0","value":"pp"},{"cost":"0.00","id":181,"servise":"WestStein","serviseImg":"bg-th","number":"Numbers: 0","value":"th"},{"cost":"0.04","id":182,"servise":"Tango","serviseImg":"bg-xr","number":"Numbers: 27765","value":"xr"},{"cost":"0.00","id":183,"servise":"Global24","serviseImg":"bg-iz","number":"Numbers: 0","value":"iz"},{"cost":"0.03","id":184,"servise":"\u041c\u0412\u0438\u0434\u0435\u043e","serviseImg":"bg-tk","number":"Numbers: 27660","value":"tk"},{"cost":"0.00","id":185,"servise":"Sheerid","serviseImg":"bg-rx","number":"Numbers: 0","value":"rx"},{"cost":"0.00","id":186,"servise":"99app","serviseImg":"bg-ki","number":"Numbers: 0","value":"ki"},{"cost":"0.00","id":187,"servise":"CAIXA","serviseImg":"bg-my","number":"Numbers: 0","value":"my"},{"cost":"0.00","id":188,"servise":"OfferUp","serviseImg":"bg-zm","number":"Numbers: 0","value":"zm"},{"cost":"0.00","id":189,"servise":"Swvl","serviseImg":"bg-tq","number":"Numbers: 0","value":"tq"},{"cost":"0.00","id":190,"servise":"Haraj","serviseImg":"bg-au","number":"Numbers: 0","value":"au"},{"cost":"0.00","id":191,"servise":"Taksheel","serviseImg":"bg-ei","number":"Numbers: 0","value":"ei"},{"cost":"0.00","id":192,"servise":"hamrahaval","serviseImg":"bg-rp","number":"Numbers: 0","value":"rp"},{"cost":"0.00","id":193,"servise":"Gamekit","serviseImg":"bg-pa","number":"Numbers: 0","value":"pa"},{"cost":"0.00","id":194,"servise":" \u015eikayet var","serviseImg":"bg-fs","number":"Numbers: 0","value":"fs"},{"cost":"0.00","id":195,"servise":"Getir","serviseImg":"bg-ul","number":"Numbers: 0","value":"ul"},{"cost":"0.00","id":196,"servise":"irancell","serviseImg":"bg-cf","number":"Numbers: 0","value":"cf"},{"cost":"0.00","id":197,"servise":"Alfa","serviseImg":"bg-bt","number":"Numbers: 0","value":"bt"},{"cost":"0.00","id":198,"servise":"Disney Hotstar","serviseImg":"bg-ud","number":"Numbers: 0","value":"ud"},{"cost":"0.00","id":199,"servise":"Agroinform","serviseImg":"bg-qu","number":"Numbers: 0","value":"qu"},{"cost":"0.00","id":200,"servise":"humblebundle","serviseImg":"bg-un","number":"Numbers: 0","value":"un"},{"cost":"0.00","id":201,"servise":"Faberlic","serviseImg":"bg-rm","number":"Numbers: 0","value":"rm"},{"cost":"0.00","id":202,"servise":"CafeBazaar","serviseImg":"bg-uo","number":"Numbers: 0","value":"uo"},{"cost":"0.00","id":203,"servise":"cryptocom","serviseImg":"bg-ti","number":"Numbers: 0","value":"ti"},{"cost":"0.00","id":204,"servise":"Gittigidiyor","serviseImg":"bg-nk","number":"Numbers: 0","value":"nk"},{"cost":"0.00","id":205,"servise":"mzadqatar","serviseImg":"bg-jm","number":"Numbers: 0","value":"jm"},{"cost":"0.00","id":206,"servise":"Algida","serviseImg":"bg-lp","number":"Numbers: 0","value":"lp"},{"cost":"0.00","id":207,"servise":"Cita Previa","serviseImg":"bg-si","number":"Numbers: 0","value":"si"},{"cost":"0.00","id":208,"servise":"Potato Chat","serviseImg":"bg-fj","number":"Numbers: 0","value":"fj"},{"cost":"0.00","id":209,"servise":"Bitaqaty","serviseImg":"bg-pt","number":"Numbers: 0","value":"pt"},{"cost":"0.00","id":210,"servise":"Primaries 2020","serviseImg":"bg-qc","number":"Numbers: 0","value":"qc"},{"cost":"0.00","id":211,"servise":"Amasia","serviseImg":"bg-yo","number":"Numbers: 0","value":"yo"},{"cost":"0.00","id":212,"servise":"Dream11","serviseImg":"bg-ve","number":"Numbers: 0","value":"ve"},{"cost":"0.00","id":213,"servise":"Oriflame","serviseImg":"bg-qh","number":"Numbers: 0","value":"qh"},{"cost":"0.00","id":214,"servise":"Bykea","serviseImg":"bg-iu","number":"Numbers: 0","value":"iu"},{"cost":"0.00","id":215,"servise":"Immowelt","serviseImg":"bg-ib","number":"Numbers: 0","value":"ib"},{"cost":"0.00","id":216,"servise":"Digikala","serviseImg":"bg-zv","number":"Numbers: 0","value":"zv"},{"cost":"0.00","id":217,"servise":"Wing Money","serviseImg":"bg-jb","number":"Numbers: 0","value":"jb"},{"cost":"0.00","id":218,"servise":"Yaay","serviseImg":"bg-vn","number":"Numbers: 0","value":"vn"},{"cost":"0.00","id":219,"servise":"GameArena","serviseImg":"bg-wn","number":"Numbers: 0","value":"wn"},{"cost":"0.04","id":220,"servise":"Vita express","serviseImg":"bg-bj","number":"Numbers: 27861","value":"bj"},{"cost":"0.00","id":221,"servise":"Auchan","serviseImg":"bg-st","number":"Numbers: 0","value":"st"},{"cost":"0.00","id":222,"servise":"Picpay","serviseImg":"bg-ev","number":"Numbers: 0","value":"ev"},{"cost":"0.00","id":223,"servise":"Blued","serviseImg":"bg-qn","number":"Numbers: 0","value":"qn"},{"cost":"0.05","id":224,"servise":"Not on the list","serviseImg":"bg-ot","number":"Numbers: 19352","value":"ot"}]
for j in json_list:
n = i['number'].split()[-1]
print(n)
# do something interesting with n

extract xml to pandas dataframe with unknown number of nodes

The below code sample works if there is only one node.
However, our use case we dont know how many nodes we will receive
Convert a xml to pandas data frame python
Sample as below.
How we can parse this into dataframe
In particular, we dont know how manby
we will received in the feed file
<?xml version = '1.0' encoding = 'UTF-8'?>
<EVENT spec="IDL:com/RfcCallEvents:1.0#Z_BAPI_UPDT_SERV_NOTIFICATION">
<eventHeader>
<objectName/>
<objectKey/>
<eventName/>
<eventId/>
</eventHeader>
<TAB_DETAIL_DATA>
<ZNEWFLAG>X</ZNEWFLAG>
<FENUM>2</FENUM>
<BAUTL>661-01727</BAUTL>
<OTEIL/>
<FECOD>KBB</FECOD>
<URCOD>B08</URCOD>
<ZCOMPMDF>A</ZCOMPMDF>
<ZOPREPL/>
<ZWRNCOV>LP</ZWRNCOV>
<ZWRNREF/>
<ZNEWPS>C07XMAAEJCLD</ZNEWPS>
<ZOLDPN/>
<ZOLDPD/>
<ZOLDPS>C07XMAACJCLD</ZOLDPS>
<MAILINFECOD/>
<ZUNITPR/>
<ZNEWPD/>
<ZNEWPN/>
<ZABUSE/>
<ZRPS>S</ZRPS>
<ZEXKGB/>
<ZKGBMM/>
<ZINSTS>000</ZINSTS>
<ZACKBB/>
<ZCHKOVR/>
<ZSNDB/>
<ZNOTAFISCAL/>
<ZCONSGMT/>
<ZPRTCONS/>
<ZZRTNTRNO/>
<ZZRTNCAR/>
<ZZINSPECT/>
<ZZPR_OPT/>
</TAB_DETAIL_DATA>
<TAB_DETAIL_DATA>
<ZNEWFLAG>X</ZNEWFLAG>
<FENUM>1</FENUM>
<BAUTL>661-01727</BAUTL>
<OTEIL/>
<FECOD>KBB</FECOD>
<URCOD>B08</URCOD>
<ZCOMPMDF>A</ZCOMPMDF>
<ZOPREPL/>
<ZWRNCOV>LP</ZWRNCOV>
<ZWRNREF/>
<ZNEWPS>C07XMAAEJCLD</ZNEWPS>
<ZOLDPN/>
<ZOLDPD/>
<ZOLDPS>C07XMAACJCLD</ZOLDPS>
<MAILINFECOD/>
<ZUNITPR/>
<ZNEWPD/>
<ZNEWPN/>
<ZABUSE/>
<ZRPS>S</ZRPS>
<ZEXKGB/>
<ZKGBMM/>
<ZINSTS>000</ZINSTS>
<ZACKBB/>
<ZCHKOVR/>
<ZSNDB/>
<ZNOTAFISCAL/>
<ZCONSGMT/>
<ZPRTCONS/>
<ZZRTNTRNO/>
<ZZRTNCAR/>
<ZZINSPECT/>
<ZZPR_OPT/>
</TAB_DETAIL_DATA>
<TAB_HEADER_DATA>
<QMNUM>030334920069</QMNUM>
<ZGSXREF>CONSUMER</ZGSXREF>
<ZVANTREF>G338005317</ZVANTREF>
<ZSHIPER/>
<ZSHPRNO/>
<ZRVREF/>
<ZTECHID>4HQ2OD6C19</ZTECHID>
<ZADREPAIR/>
<ZZKATR7/>
</TAB_HEADER_DATA>
</EVENT>
I suspect you need to parse xml-data to several dataframes, e.g. as follows:
import xmltodict # install this module first
data = """<?xml version = '1.0' encoding = 'UTF-8'?>
<EVENT spec="IDL:com/RfcCallEvents:1.0#Z_BAPI_UPDT_SERV_NOTIFICATION">
<eventHeader>
<objectName/>
<objectKey/>
<eventName/>
<eventId/>
</eventHeader>
<TAB_DETAIL_DATA>
<ZNEWFLAG>X</ZNEWFLAG>
<FENUM>2</FENUM>
<BAUTL>661-01727</BAUTL>
<OTEIL/>
<FECOD>KBB</FECOD>
<URCOD>B08</URCOD>
<ZCOMPMDF>A</ZCOMPMDF>
<ZOPREPL/>
<ZWRNCOV>LP</ZWRNCOV>
<ZWRNREF/>
<ZNEWPS>C07XMAAEJCLD</ZNEWPS>
<ZOLDPN/>
<ZOLDPD/>
<ZOLDPS>C07XMAACJCLD</ZOLDPS>
<MAILINFECOD/>
<ZUNITPR/>
<ZNEWPD/>
<ZNEWPN/>
<ZABUSE/>
<ZRPS>S</ZRPS>
<ZEXKGB/>
<ZKGBMM/>
<ZINSTS>000</ZINSTS>
<ZACKBB/>
<ZCHKOVR/>
<ZSNDB/>
<ZNOTAFISCAL/>
<ZCONSGMT/>
<ZPRTCONS/>
<ZZRTNTRNO/>
<ZZRTNCAR/>
<ZZINSPECT/>
<ZZPR_OPT/>
</TAB_DETAIL_DATA>
<TAB_DETAIL_DATA>
<ZNEWFLAG>X</ZNEWFLAG>
<FENUM>1</FENUM>
<BAUTL>661-01727</BAUTL>
<OTEIL/>
<FECOD>KBB</FECOD>
<URCOD>B08</URCOD>
<ZCOMPMDF>A</ZCOMPMDF>
<ZOPREPL/>
<ZWRNCOV>LP</ZWRNCOV>
<ZWRNREF/>
<ZNEWPS>C07XMAAEJCLD</ZNEWPS>
<ZOLDPN/>
<ZOLDPD/>
<ZOLDPS>C07XMAACJCLD</ZOLDPS>
<MAILINFECOD/>
<ZUNITPR/>
<ZNEWPD/>
<ZNEWPN/>
<ZABUSE/>
<ZRPS>S</ZRPS>
<ZEXKGB/>
<ZKGBMM/>
<ZINSTS>000</ZINSTS>
<ZACKBB/>
<ZCHKOVR/>
<ZSNDB/>
<ZNOTAFISCAL/>
<ZCONSGMT/>
<ZPRTCONS/>
<ZZRTNTRNO/>
<ZZRTNCAR/>
<ZZINSPECT/>
<ZZPR_OPT/>
</TAB_DETAIL_DATA>
<TAB_HEADER_DATA>
<QMNUM>030334920069</QMNUM>
<ZGSXREF>CONSUMER</ZGSXREF>
<ZVANTREF>G338005317</ZVANTREF>
<ZSHIPER/>
<ZSHPRNO/>
<ZRVREF/>
<ZTECHID>4HQ2OD6C19</ZTECHID>
<ZADREPAIR/>
<ZZKATR7/>
</TAB_HEADER_DATA>
</EVENT>"""
dct = xmltodict.parse(data)
def make_df(name="TAB_DETAIL_DATA", dct=dct):
df = pd.DataFrame()
if isinstance(dct['EVENT'][name], list):
for j in dct['EVENT'][name]:
_ = pd.DataFrame({'value': [y for x, y in j.items()]}, index=j.keys())
df = pd.concat([df, _])
else:
df = pd.DataFrame({'value': [y for x, y in dct['EVENT'][name].items()]}, index=dct['EVENT'][name].keys())
return df
Now, you can experiment with the parser:
make_df(name="TAB_HEADER_DATA") # produces single df
make_df(name="TAB_DETAIL_DATA") # concatenates all content occurred in TAB_DETAIL_DATA sections, returns single df

Cumprod giving -inf in Python

I am trying to compute cumulative product of the following data set.
Date Random data
1/2/2006 2.372388507
1/3/2006 2.792095479
1/4/2006 4.153345633
1/5/2006 1.209302413
1/6/2006 3.308908843
1/9/2006 5.609288688
1/10/2006 5.148763856
1/11/2006 4.963421605
1/12/2006 4.031740124
1/13/2006 5.475643588
1/16/2006 5.310478512
1/17/2006 5.231183268
1/18/2006 7.33295124
1/19/2006 7.086467341
1/20/2006 6.953441702
1/23/2006 6.881551417
1/24/2006 6.720592121
1/25/2006 4.375483647
1/26/2006 2.824165469
1/27/2006 2.830542833
1/30/2006 3.735049499
1/31/2006 3.147491688
2/1/2006 1.414748374
2/2/2006 -0.051161849
2/3/2006 -0.180186506
2/6/2006 1.660894524
2/7/2006 2.709409323
2/8/2006 1.972035231
2/9/2006 -0.782625682
2/10/2006 -1.901299484
2/13/2006 -2.141229007
2/14/2006 -2.639233019
2/15/2006 -4.95219641
2/16/2006 -6.568204721
2/17/2006 -5.671892621
2/20/2006 -5.989308797
2/21/2006 -5.519832515
2/22/2006 -4.123507939
2/23/2006 -4.840716254
2/24/2006 -3.393895281
2/27/2006 -1.579450628
2/28/2006 -5.715894843
3/1/2006 -4.818584424
3/2/2006 -5.306398625
3/3/2006 -3.773552658
3/6/2006 -1.782726837
3/7/2006 -2.421770003
3/8/2006 -2.032466154
3/9/2006 -3.24379646
3/10/2006 0.267982805
3/13/2006 0.014589559
3/14/2006 1.343058431
3/15/2006 1.539251495
3/16/2006 -0.350651804
3/17/2006 -0.215041321
3/20/2006 0.578951429
3/21/2006 -0.576824159
3/22/2006 1.881264415
3/23/2006 2.714386498
3/24/2006 4.111298817
3/27/2006 5.020309083
3/28/2006 4.532650354
3/29/2006 7.245341261
3/30/2006 8.111802803
3/31/2006 4.558323469
4/3/2006 6.252751308
4/4/2006 8.314806951
4/5/2006 5.777692349
4/6/2006 6.725161553
4/7/2006 4.794367906
4/10/2006 5.743532122
4/11/2006 7.290548166
4/12/2006 5.903857018
4/13/2006 4.77936565
4/14/2006 5.674446806
4/17/2006 5.88485792
4/18/2006 6.078651917
4/19/2006 4.917405394
4/20/2006 4.868584712
4/21/2006 3.526253732
4/24/2006 5.124797759
4/25/2006 3.884862865
4/26/2006 4.369885748
4/27/2006 1.234703037
4/28/2006 -1.67674986
5/1/2006 -2.711339347
5/2/2006 -2.574835748
5/3/2006 -3.532974512
5/4/2006 -4.361912086
5/5/2006 -9.136912315
5/8/2006 -8.945826752
5/9/2006 -7.804639384
5/10/2006 -10.05905437
5/11/2006 -9.254733416
5/12/2006 -8.382467816
5/15/2006 -7.718500019
5/16/2006 -10.04179082
5/17/2006 -10.90960283
5/18/2006 -7.538484374
5/19/2006 -6.915045472
5/22/2006 -8.49018374
5/23/2006 -10.84341146
5/24/2006 -4.739280009
5/25/2006 -8.906757979
5/26/2006 -10.61262457
5/29/2006 -9.636827323
5/30/2006 -8.353511534
5/31/2006 -10.1389515
6/1/2006 -10.0339179
6/2/2006 -10.84551313
6/5/2006 -8.628081538
6/6/2006 -6.657905529
6/7/2006 -6.395791873
6/8/2006 -7.676135515
6/9/2006 -7.225332776
6/12/2006 -5.721847599
6/13/2006 -9.168934478
6/14/2006 -8.522434172
6/15/2006 -9.344608517
6/16/2006 -9.492790802
6/19/2006 -6.27304367
6/20/2006 -7.748707965
6/21/2006 -5.216536389
6/22/2006 -5.866333313
6/23/2006 -3.421767661
6/26/2006 -0.817150639
6/27/2006 1.566919066
6/28/2006 2.1756715
6/29/2006 2.003892417
6/30/2006 0.145706902
7/3/2006 4.825841191
7/4/2006 2.984194983
7/5/2006 2.733606852
7/6/2006 3.990344988
7/7/2006 4.464159978
7/10/2006 2.181922905
7/11/2006 4.207532649
7/12/2006 5.893857763
7/13/2006 6.696591003
7/14/2006 8.02397588
7/17/2006 7.18005379
7/18/2006 7.110823813
7/19/2006 4.604122492
7/20/2006 4.383075987
7/21/2006 4.734463235
7/24/2006 5.60625391
7/25/2006 7.453657745
7/26/2006 6.7147771
7/27/2006 5.255477178
7/28/2006 6.638942489
7/31/2006 5.514850947
8/1/2006 6.666282084
8/2/2006 6.037577365
8/3/2006 6.434382521
8/4/2006 5.80948075
8/7/2006 5.667054317
8/8/2006 5.175715003
8/9/2006 4.94937506
8/10/2006 3.558925269
8/11/2006 4.031802401
8/14/2006 3.272287286
8/15/2006 4.289470879
8/16/2006 3.538103725
8/17/2006 2.762386707
8/18/2006 2.114880041
8/21/2006 5.068950919
8/22/2006 2.483874694
8/23/2006 1.730699516
8/24/2006 -0.675212673
8/25/2006 0.187110629
8/28/2006 0.344282156
8/29/2006 0.01723009
8/30/2006 -0.327127005
8/31/2006 0.016483468
9/1/2006 -0.973496098
9/4/2006 -1.218588549
9/5/2006 -0.20940671
9/6/2006 0.25023559
9/7/2006 -2.986442703
9/8/2006 -2.073033591
9/11/2006 1.390003709
9/12/2006 2.940760338
9/13/2006 2.403386183
9/14/2006 2.349487863
9/15/2006 1.899995646
9/18/2006 3.50536463
9/19/2006 2.83392064
9/20/2006 2.571588424
9/21/2006 3.118297653
9/22/2006 -0.377687298
9/25/2006 -2.391993686
9/26/2006 0.712594429
9/27/2006 1.457682028
9/28/2006 1.474114727
9/29/2006 0.446453108
10/2/2006 3.007973689
10/3/2006 -2.43263121
10/4/2006 0.86295345
10/5/2006 4.664733649
10/6/2006 4.558573046
10/9/2006 4.680665577
10/10/2006 4.575158956
10/11/2006 6.425144162
10/12/2006 8.372432637
10/13/2006 8.182474544
10/16/2006 8.968786366
10/17/2006 9.463661551
10/18/2006 8.512907068
10/19/2006 5.873743873
10/20/2006 3.369445264
10/23/2006 1.030307363
10/24/2006 5.528218034
10/25/2006 4.772900213
10/26/2006 4.780839053
10/27/2006 4.908377081
10/30/2006 1.949064709
10/31/2006 1.237048868
11/1/2006 -0.784592691
11/2/2006 2.737788889
11/3/2006 0.575772221
11/6/2006 0.756429404
11/7/2006 3.470072539
11/8/2006 3.162250037
11/9/2006 3.530282875
11/10/2006 3.101909259
11/13/2006 3.850635629
11/14/2006 5.765932269
11/15/2006 6.872396495
11/16/2006 7.65256188
11/17/2006 7.665129818
11/20/2006 7.688611466
11/21/2006 10.98556762
11/22/2006 10.3474519
11/23/2006 8.307676877
11/24/2006 6.809710616
11/27/2006 3.833060531
11/28/2006 2.194899225
11/29/2006 2.753858429
11/30/2006 7.843689893
12/1/2006 7.960285607
12/4/2006 8.693168009
12/5/2006 6.942631629
12/6/2006 7.571515106
12/7/2006 9.703434772
12/8/2006 9.330900226
12/11/2006 10.07080936
12/12/2006 8.823865383
12/13/2006 9.142372346
12/14/2006 11.4249828
12/15/2006 13.4976679
12/18/2006 16.02891813
12/19/2006 13.57689804
12/20/2006 13.08135113
12/21/2006 11.35585478
12/22/2006 11.56407075
12/25/2006 12.55729202
12/26/2006 12.74006864
12/27/2006 12.80879851
12/28/2006 12.78104782
12/29/2006 10.84853655
1/1/2007 12.34247778
1/2/2007 12.4083186
1/3/2007 12.05157619
1/4/2007 13.31470937
1/5/2007 13.08023063
1/8/2007 11.8083914
1/9/2007 12.14102299
1/10/2007 12.78561441
1/11/2007 10.5599935
1/12/2007 9.670640578
1/15/2007 7.5265463
1/16/2007 5.785317873
1/17/2007 6.421764885
1/18/2007 6.13308998
1/19/2007 4.502378909
1/22/2007 5.18285115
1/23/2007 6.651267567
1/24/2007 9.669499091
1/25/2007 9.873389316
1/26/2007 8.512393515
1/29/2007 8.17935067
1/30/2007 7.565247724
1/31/2007 10.26027855
2/1/2007 12.21138996
2/2/2007 11.0873071
2/5/2007 15.28502878
2/6/2007 13.68842955
2/7/2007 13.27807961
2/8/2007 12.83276901
2/9/2007 13.80840316
2/12/2007 10.40760837
2/13/2007 8.706916548
2/14/2007 7.062821439
2/15/2007 6.720750572
2/16/2007 5.181412914
2/19/2007 6.377711852
2/20/2007 6.777151257
2/21/2007 7.213968623
2/22/2007 5.717975255
2/23/2007 7.535619266
2/26/2007 6.226846924
2/27/2007 6.420469572
2/28/2007 7.825909152
3/1/2007 9.322928614
3/2/2007 10.09251084
3/5/2007 10.01940332
3/6/2007 8.500303192
3/7/2007 8.276245994
3/8/2007 8.618637579
3/9/2007 9.130646064
3/12/2007 5.00975105
3/13/2007 3.332393527
3/14/2007 1.483827461
3/15/2007 3.638824916
3/16/2007 3.461569024
3/19/2007 2.163572694
3/20/2007 2.369195247
3/21/2007 -3.015080521
3/22/2007 -2.584981113
3/23/2007 1.616297026
3/26/2007 3.424344952
3/27/2007 3.512629879
3/28/2007 1.565564369
3/29/2007 3.155875359
3/30/2007 4.13585074
4/2/2007 2.121894843
4/3/2007 2.85329683
4/4/2007 2.790940846
4/5/2007 2.709380118
4/6/2007 -0.537294118
4/9/2007 1.409591457
4/10/2007 -0.844805873
4/11/2007 -3.199042638
4/12/2007 -5.222678135
4/13/2007 -5.360018022
4/16/2007 -4.086590776
4/17/2007 -6.846401327
4/18/2007 -8.129698699
4/19/2007 -9.43907148
4/20/2007 -9.54782865
4/23/2007 -10.0618768
4/24/2007 -7.849914365
4/25/2007 -8.470629566
4/26/2007 -8.241284473
4/27/2007 -5.784288072
4/30/2007 -6.333447193
5/1/2007 -8.855330907
5/2/2007 -8.631907451
5/3/2007 -9.548866116
5/4/2007 -10.13722709
5/7/2007 -11.32424337
5/8/2007 -13.57236374
5/9/2007 -11.50262124
5/10/2007 -10.80211768
5/11/2007 -10.26422821
5/14/2007 -8.986010695
5/15/2007 -10.63105462
5/16/2007 -12.91613223
5/17/2007 -10.43330955
5/18/2007 -10.07261057
5/21/2007 -12.94116388
5/22/2007 -11.97531943
5/23/2007 -12.58290308
5/24/2007 -12.94199083
5/25/2007 -14.38311469
5/28/2007 -13.28631254
5/29/2007 -12.89413624
5/30/2007 -16.04739138
5/31/2007 -13.83259156
6/1/2007 -14.26299611
6/4/2007 -14.99654576
6/5/2007 -13.24079702
6/6/2007 -12.01283208
6/7/2007 -12.58499189
6/8/2007 -10.50548575
6/11/2007 -13.46398497
6/12/2007 -10.95636348
6/13/2007 -10.58475154
6/14/2007 -8.485156989
6/15/2007 -5.485141673
6/18/2007 -4.746107027
6/19/2007 0.009767635
6/20/2007 -0.673658716
6/21/2007 -1.451419275
6/22/2007 1.972232158
6/25/2007 -0.391243872
6/26/2007 1.451989507
6/27/2007 -1.766451879
6/28/2007 0.161875559
6/29/2007 -3.825996412
7/2/2007 -0.809421674
7/3/2007 -2.246492588
7/4/2007 0.432136714
7/5/2007 0.283847174
7/6/2007 -1.3650488
7/9/2007 -0.811143411
7/10/2007 -1.465879459
7/11/2007 -1.121273878
7/12/2007 -1.860874059
7/13/2007 -3.035369125
7/16/2007 1.281001022
7/17/2007 1.690991572
7/18/2007 1.945639351
7/19/2007 1.069216233
7/20/2007 3.87371198
7/23/2007 3.296879921
7/24/2007 2.591854823
7/25/2007 -3.389010393
7/26/2007 2.137825455
7/27/2007 2.283479857
7/30/2007 5.838696664
7/31/2007 6.113554468
8/1/2007 7.967210681
8/2/2007 -0.726487682
8/3/2007 -0.232469303
8/6/2007 -2.517441263
8/7/2007 -8.435316702
8/8/2007 -4.850705516
8/9/2007 -6.961937954
8/10/2007 -10.44411748
8/13/2007 -15.68807076
8/14/2007 -13.18786164
8/15/2007 -9.272095703
8/16/2007 -4.725484174
8/17/2007 -8.134541843
8/20/2007 -8.873292727
8/21/2007 -10.55565794
8/22/2007 -9.78740166
8/23/2007 -8.392234748
8/24/2007 -11.26803991
8/27/2007 -6.059253076
8/28/2007 -4.431249471
8/29/2007 -3.683881225
8/30/2007 0.740388956
8/31/2007 0.837060926
9/3/2007 3.715197568
9/4/2007 2.014739847
9/5/2007 4.587444167
9/6/2007 3.221048769
9/7/2007 1.226037567
9/10/2007 1.034531855
9/11/2007 1.479676939
9/12/2007 0.556376215
9/13/2007 -1.530067312
9/14/2007 -2.18203607
9/17/2007 -5.475770938
9/18/2007 -6.824996518
9/19/2007 -2.973998241
9/20/2007 3.708296857
9/21/2007 -3.183077897
9/24/2007 -6.546095221
9/25/2007 -11.00709425
9/26/2007 -10.95480863
9/27/2007 -6.680893811
9/28/2007 -3.787250701
10/1/2007 -14.69643306
10/2/2007 -12.37222197
10/3/2007 -5.619971442
10/4/2007 -5.695837937
10/5/2007 -3.872021061
10/8/2007 -5.852564553
10/9/2007 -6.48262714
10/10/2007 -2.398114024
10/11/2007 -3.103357068
10/12/2007 -5.878634994
10/15/2007 -9.082817992
10/16/2007 -6.07416967
10/17/2007 -3.661138214
10/18/2007 -1.840354785
10/19/2007 -1.716032675
10/22/2007 -9.940732878
10/23/2007 -6.779819032
10/24/2007 -9.55117772
10/25/2007 -6.301075251
10/26/2007 -4.727985653
10/29/2007 -3.424320292
10/30/2007 -7.488285236
10/31/2007 -11.8982972
11/1/2007 -15.03925521
11/2/2007 -15.26744844
11/5/2007 -14.74166075
11/6/2007 -17.44941576
11/7/2007 -17.61279378
11/8/2007 -18.86796214
11/9/2007 -16.67827827
11/12/2007 -12.24014836
11/13/2007 -2.85835521
11/14/2007 -4.131716897
11/15/2007 -0.203410622
11/16/2007 8.569314879
11/19/2007 5.520498128
11/20/2007 4.437427097
11/21/2007 2.798799233
11/22/2007 5.190459646
11/23/2007 2.201222838
11/26/2007 7.707810591
11/27/2007 5.20689008
11/28/2007 7.610897036
11/29/2007 6.703331237
11/30/2007 13.92928613
12/3/2007 18.05895477
12/4/2007 17.24261674
12/5/2007 14.18520991
12/6/2007 17.69996813
12/7/2007 21.95404938
12/10/2007 18.57414126
12/11/2007 18.83884342
12/12/2007 22.41801362
12/13/2007 23.54638194
12/14/2007 25.76433638
12/17/2007 16.69320167
12/18/2007 10.81895687
12/19/2007 10.9753503
12/20/2007 11.33091315
12/21/2007 12.53094339
12/24/2007 14.45641754
12/25/2007 13.19699079
12/26/2007 13.87942316
12/27/2007 11.46173706
12/28/2007 7.770676488
12/31/2007 8.700784022
1/1/2008 14.19019359
1/2/2008 11.50921642
1/3/2008 9.467085019
1/4/2008 8.492617897
1/7/2008 5.371302597
1/8/2008 6.499502146
1/9/2008 3.022727189
1/10/2008 5.927807015
1/11/2008 5.001251384
1/14/2008 0.091578188
1/15/2008 6.806397951
1/16/2008 2.248016175
1/17/2008 5.749742329
1/18/2008 1.095388248
1/21/2008 -0.368023403
1/22/2008 8.237992918
1/23/2008 -0.780766435
1/24/2008 -0.233793677
1/25/2008 -5.104415967
1/28/2008 -5.638624718
1/29/2008 -2.511924819
1/30/2008 -2.133339717
1/31/2008 -3.014162532
2/1/2008 4.847211419
2/4/2008 1.90534583
2/5/2008 -0.089019867
2/6/2008 -3.930920283
2/7/2008 -7.596390602
2/8/2008 -5.358477963
2/11/2008 -3.588291865
2/12/2008 -1.031121178
2/13/2008 4.176705555
2/14/2008 4.100989501
2/15/2008 3.685820292
2/18/2008 3.918671965
2/19/2008 4.302039738
2/20/2008 8.143021699
2/21/2008 7.475478645
2/22/2008 2.322549449
2/25/2008 5.058904324
2/26/2008 0.911568809
2/27/2008 -1.720405845
2/28/2008 -4.566637975
2/29/2008 -7.874776755
3/3/2008 -7.949385894
3/4/2008 -7.987067299
3/5/2008 -12.40581822
3/6/2008 -9.860569783
3/7/2008 -12.72461433
3/10/2008 -11.14026753
3/11/2008 -6.222506019
3/12/2008 -2.083816629
3/13/2008 -1.722946088
3/14/2008 -5.537069436
3/17/2008 -6.716071481
3/18/2008 -6.693944594
3/19/2008 5.819147828
3/20/2008 9.65059264
3/21/2008 14.9915837
3/24/2008 14.39795771
3/25/2008 12.093442
3/26/2008 9.296061707
3/27/2008 12.99072309
3/28/2008 9.836902201
3/31/2008 9.921155178
4/1/2008 7.310883267
4/2/2008 14.15477406
4/3/2008 15.48242329
4/4/2008 7.464041165
4/7/2008 11.33508368
4/8/2008 15.59010551
4/9/2008 12.58380558
4/10/2008 14.61160039
4/11/2008 12.68080501
4/14/2008 11.06353488
4/15/2008 7.092636692
4/16/2008 7.592291792
4/17/2008 3.699266022
4/18/2008 5.928888483
4/21/2008 9.133551847
4/22/2008 6.211128385
4/23/2008 5.59943155
4/24/2008 11.19533502
4/25/2008 8.286268131
4/28/2008 10.85713699
4/29/2008 10.96304626
4/30/2008 9.392330251
5/1/2008 0.459398303
5/2/2008 6.634717801
5/5/2008 7.475896399
5/6/2008 6.934371007
5/7/2008 5.570514268
5/8/2008 6.270557437
5/9/2008 7.889956448
5/12/2008 1.34341901
5/13/2008 -1.824946933
5/14/2008 -1.801607848
5/15/2008 -2.846939297
5/16/2008 -2.62131888
5/19/2008 -2.663214031
5/20/2008 -3.774870813
5/21/2008 -5.138174533
5/22/2008 -5.480107155
5/23/2008 -6.670996157
5/26/2008 -4.64561419
5/27/2008 -4.145292498
5/28/2008 0.355057164
5/29/2008 -2.939764523
5/30/2008 -6.63747287
6/2/2008 -6.098950421
6/3/2008 -7.13882023
6/4/2008 -5.604616952
6/5/2008 -4.549857994
6/6/2008 5.087697562
6/9/2008 6.579771782
6/10/2008 0.060955293
6/11/2008 2.445348204
6/12/2008 0.317989372
6/13/2008 3.251865221
6/16/2008 6.862732095
6/17/2008 -0.134582166
6/18/2008 -6.537950835
6/19/2008 -8.448799147
6/20/2008 -6.732406995
6/23/2008 -7.738394975
6/24/2008 -8.206195168
6/25/2008 -5.548307148
6/26/2008 -7.002765304
6/27/2008 -6.495980763
6/30/2008 -8.8477976
7/1/2008 -1.679587243
7/2/2008 0.128504075
7/3/2008 -0.255570561
7/4/2008 3.108701207
7/7/2008 5.492404862
7/8/2008 3.133532773
7/9/2008 2.385568794
7/10/2008 -3.712475585
7/11/2008 -2.11874535
7/14/2008 -7.791149245
7/15/2008 -9.785882826
7/16/2008 -16.1405786
7/17/2008 -14.74751549
7/18/2008 -13.27703399
7/21/2008 -14.20650424
7/22/2008 -16.05642567
7/23/2008 -10.40258214
7/24/2008 -7.895783574
7/25/2008 -6.064576168
7/28/2008 -7.555469117
7/29/2008 -7.550365786
7/30/2008 -4.41096581
7/31/2008 0.972694457
8/1/2008 -3.909922199
8/4/2008 -2.854671378
8/5/2008 -4.752925064
8/6/2008 7.894333599
8/7/2008 6.952958366
8/8/2008 6.803337004
8/11/2008 12.5598522
8/12/2008 17.02711995
8/13/2008 11.21457308
8/14/2008 9.870340669
8/15/2008 13.52048273
8/18/2008 15.36663294
8/19/2008 12.06804629
8/20/2008 10.90150334
8/21/2008 9.740240549
8/22/2008 5.754842321
8/25/2008 5.094710468
8/26/2008 4.298242012
8/27/2008 3.633974039
8/28/2008 2.662183974
8/29/2008 2.274767726
9/1/2008 3.049897094
9/2/2008 3.728150019
9/3/2008 3.568469208
9/4/2008 3.118192613
9/5/2008 0.208336992
9/8/2008 -7.955346446
9/9/2008 3.034657287
9/10/2008 0.212924163
9/11/2008 -5.039089706
9/12/2008 -4.206315664
9/15/2008 -12.47329445
9/16/2008 -23.87744975
9/17/2008 -26.40484165
9/18/2008 -25.38241597
9/19/2008 -23.36121528
9/22/2008 -21.42741971
9/23/2008 -17.99846112
9/24/2008 -28.57986509
9/25/2008 -29.16609299
9/26/2008 -27.08038434
9/29/2008 -20.97454917
9/30/2008 -30.86583486
10/1/2008 -11.34463183
10/2/2008 -12.48376615
10/3/2008 -6.026656168
10/6/2008 -6.990288682
10/7/2008 -8.932722825
10/8/2008 -9.613027881
10/9/2008 -9.639879581
10/10/2008 -9.585152864
10/13/2008 -3.406342217
10/14/2008 8.128268033
10/15/2008 -0.84337937
10/16/2008 3.021563746
10/17/2008 -3.052518135
10/20/2008 -2.400985986
10/21/2008 3.0230433
10/22/2008 10.5804596
10/23/2008 18.09790623
10/24/2008 12.13621658
10/27/2008 14.20662326
10/28/2008 21.01635274
10/29/2008 17.2248841
10/30/2008 -4.561706872
10/31/2008 -18.90903769
11/3/2008 -4.608843616
11/4/2008 -20.06787313
11/5/2008 -18.5941511
11/6/2008 -21.3287201
11/7/2008 -18.90428072
11/10/2008 -17.15139132
11/11/2008 -11.95485141
11/12/2008 -10.52108832
11/13/2008 -3.751031577
11/14/2008 -7.025476067
11/17/2008 -0.484754776
11/18/2008 -7.565724121
11/19/2008 -3.494100907
11/20/2008 1.878346526
11/21/2008 8.620226332
11/24/2008 -2.178445463
11/25/2008 -6.594895809
11/26/2008 -13.80582831
11/27/2008 -1.718399396
11/28/2008 -2.690040888
12/1/2008 0.045615029
12/2/2008 -8.037898361
12/3/2008 -6.694808104
12/4/2008 -1.105754753
12/5/2008 1.02570118
12/8/2008 -4.239560375
12/9/2008 -5.393379841
12/10/2008 -2.751561124
12/11/2008 -2.779615506
12/12/2008 -3.187906517
12/15/2008 -1.152777608
12/16/2008 -8.701242176
12/17/2008 -17.74161255
12/18/2008 -25.91607496
12/19/2008 -23.78881822
12/22/2008 -21.24675823
12/23/2008 -11.96460548
12/24/2008 -15.00820918
12/25/2008 -18.71378165
12/26/2008 -15.66724025
12/29/2008 -9.785209077
12/30/2008 -8.555974407
12/31/2008 -8.218782102
import pandas as pd
df=read_csv("Randomdata.csv")
df2=df.add(1).cumprod()
I tried another method too.
df3=1+df.cumprod()
Both are yielding -inf values. It's happening for this data set specifically.
Please suggest the way forward.
It looks like you are trying to calculate cumulative returns. If so, those numbers are not in returns space and need to be divided by 100 first
import pandas as pd
df = pd.read_csv("Randomdata.csv")
df2 = df.div(100).add(1).cumprod().sub(1).mul(100)
Comment from OP
I made the following change, removed subtraction.
df2 = df.div(100).add(1).cumprod().mul(100)
df2['returns_from_price_recovered'] = 100 * df2.pct_change()

Categories

Resources