I try to create a column with coordinate of the point as a numpy array. I have a data as Easting and Northing. I would like to reduce large numbers simply by shifting it down. I try to test it with Unittest
I try to follow other questions with .apply(lambda)
but can work it out what I have wrong. (I work in pandas 0.9 and can't update it). Below is an example code and the function I struggle with is adjustCoordSystem()
import unittest
import pandas as pd
from pandas.util.testing import assert_frame_equal
def exampleDf():
df = pd.DataFrame({'Easting':{0:11,1:12,2:13,3:14},
'Northing':{0:5,1:7,2:9,3:11}})
return df
def exampWithCoord():
df = exampleDf()
df['Sample']=[[0,0,0],[1,2,0],[2,4,0],[3,6,0]]
return df
class dfProccesedFull():
def adjustCoordSystem(self, df):
''' change coordinate system to get from 0 to max'''
df['Sample'] = \
[df['Easting'].apply(lambda x: x - min(df['Easting'])),
df['Northing'].apply(lambda x: x - min(df['Northing'])),
df['Northing'].apply(lambda x: 0.0)]
# [(df['Easting'] - min(df['Easting'])), (df['Northing'] - min(df['Northing'])),\
# df['Northing'].apply(lambda x: 0.0)]
return df
class TestDfProccesedDataFull(unittest.TestCase):
def test_adjustCoordSystem(self):
df = exampleDf()
dfModel = exampWithCoord()
tData = dfProccesedFull()
dfTested=tData.adjustCoordSystem(df)
assert_frame_equal(dfTested, dfModel)
if __name__ == "__main__"
unittest.main()
I have an error: AssertionError
for line: df['Northing'].apply(lambda x: 0.0)]
How should I change my function to have in the column "Sample" a list of arrays but not looping through each row?
The output I am looking for is new dataframe such as:
Easting Northing Sample
0 11 5 [0, 0, 0]
1 12 7 [1, 2, 0]
2 13 9 [2, 4, 0]
3 14 11 [3, 6, 0]
where "Sample" column comes as [x-coordinate from Easting, y-coordinate from Northing, z-coordinate=0]