Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

DataFrame stores column of object as NaNs

DataFrame stores NaNs instead of column of vectors

df = pd.DataFrame({"a": [1,2,3], "b": [4,5,6]}, index=["one", "two", "three"])
s = pd.Series([(i*10, i*11, i*12) for i in df["a"]], dtype=object)

Here the series is what I need it to be (contains a vectors).
But putting it together it only stores NaNs

df.loc[:, "c"] = s
#       a   b   c
#one    1   4   NaN
#two    2   5   NaN
#three  3   6   NaN

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If indices are not exactly same in Series and DataFrame got NaNs, because indices don’t align.

Solution is same indices in s.index like df.index:

s = pd.Series([v / np.linalg.norm(v) for v in maxShear_vec],dtype='object'),index=df.index)

df["maxShear_vec"] = s

Also I think dtype='object' should be omited:

s = pd.Series([v / np.linalg.norm(v) for v in maxShear_vec],index=df.index)

df["maxShear_vec"] = s
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading