python - Append to dataframe from another with calculations -
I have 2 CSV files that I have read and make 2 dataframes out of them.
I am taking another dataframe and doing some calculations with it to attach to the first dataframe. Although it does not appear that the data that is already attached to the frame is actually happening.
What do I need to do to correct this?
Here the code is using I:
as PDF meter = pd.read_csv ('DailyHistoricData.csv', header = none, index_col = 0 ) F = pd.read_csv ('ImportFMP.csv' import panda, header = index in range (lane (f)): a0 = f.ix [index, 0] a1 = f.ix [index, 1] a2 = F.ix [index, 7] a3 = f.ix [index, 8] -f.ix [index, 9] a4 = 100 * fx [index, 2] a5 = fx [index, 10] -F.X [index, 11] A6 = F.x [index, 3] a7 = f.ix [index, 4] a8 = f.ix [index, 5] a9 = f.ix [ Index, 6] m.append ([a0, A3, A4, A5 a2, A1, A6, a7, a8, a9]) print m.tail (3)
The information for F is:
< Code> & lt; class 'pandas.core.frame.DataFrame' & gt; Int64Index: 720 entries, data columns to 0 719 (total 12 columns): 0 in 720 non-zero int64 1 720 non-zero int64 2 720 in non-zero float64 3 720 non-zero int64 4 720 in non-zero int64 5 720 non-null int64 6 720 non-zero int64 7 720 non-zero int64 8 720 non-zero int64 9 720 non Null int64 10 720 non-zero float64 11 720 non-zero int64 dtypes: float64 (2), int64 (10) none
There are 5 queues:
0 1 2 3 4 5 6 7 8 9 10 11 11541 20110118 1.55 1296 1290 1295 1334 11838 1646 1393 525 687 1 11542 20110119 2,46 1295 1279 1282 1337 11825 697 2358 115 958 2 11543 20110120 0,70 1283 1271 1280 1312 11822 1141 1892 547 632 3 11544 20110121 0,83 1291 1282 1283 1310 11871 1597 1438 717 535 4 11545 20110124 1,23 1292 1282 1291 1304 11980 2143 904 628 325 < / Code>
M information is:
& lt; Class 'pan das.core.frame.DataFrame' & gt; Int64Index: 11544 entries, data column (total 19 columns) to 1 11544: Non-zero int64 2 11544 in non-zero float64 3 11544 in non-zero int64 4 11544 non-zero float64 5 11544 in non-zero Non-zero float64 6 11544 non-zero float64 7 11544 non-zero float64 8 11544 in non-zero float64 9 11544 non-zero int64 10 11544 non-zero float64 11 11544 non-zero float64 12 11544 non-zero float64 Non-zero float64 15 11544 in non-zero int64 14 11544 non-zero float64 16 11544 non-zero float64 17 11544 non-zero float64 17 11544 non- Non Nil float64 19 11544 in non-zero int64 dtypes: float64 (13), int64 (6), any of the first 5 rows of data for
and m :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 \ 0 1 19650302 507.99 70 56 1.77 0 0 0 0 0 0 0 0 2 2 19650303 507.35 46 73 1.07 0 0 0 0 0 0 0 0 3 3 19650304 505,94 -104 96-039 0 0 0 0 0 0 0 0 4 19650305 504,76 -200 66 0,14 0 0 0 0 0 0 0 0 0 5 5 19650308 504,86 160 89 0,90 0 0 0 0 0 0 0 0 0 16 17 18 19 0 0 0 0 1 2 0 0 0 2 3 0 0 3 4 0 0 5 5 5 0 0 5 5
You should alert:
[Code] in [68]: a3 = f.iloc [,, 8] - F.Loc [:, 9] in [6 9]: A4 = 100 * F.Loc [:, 2] in [70 ]: A5 = F.LoO [, 10] - F.Loc [:, 11] [71] In: toappend = pd.concat ([A3, A4, A5], axis = 1) .rename (columns = dict (zip (range (3) , In the list ('ABC'))) [72]: toappend.tail () out [72]: abc 715 -1147 100 -247 716 -1022 89 -200 717 1491 109 328 718 712 87 194 719 -335 97 [73]: Res = m.append (f.iloc [,: [0, 3, 4, 5, 1, 6, 7]] in the -84 [5 rows x 3 column] (to add) In [74]: res.tail () [['a', 'b', 'c']] outside [74]: abc 715-1147 100 -247 716 -1022 89 -200 717 1491 109 328 718 712 87 194 719 -335 97 -84 [5 rows x 3 column]
In general, if you find yourself looping the body parts whose arithmetic Other operations include writing if you take advantage of most likely be able to work on the whole vector / series
object and numpy
speed in this regard.
Comments
Post a Comment