Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
adding a calculated column
#1
I have noticed that when I have added a column to my data frame made up of 2 existing column divided by each other the NaN values in the data frame go, is this anotherway of getting rid of NaN values, or are they still there in the data frame
Reply
#2
From your description I wrote this:
import pandas as pd
from numpy import nan


data = pd.DataFrame({"X": [1, 2, 3, nan], "Y": [2, 0, 3, 4]})
print(data)
data["Z"] = data["X"] / data["Y"]
print(data)
Output:
X Y 0 1.0 2 1 2.0 0 2 3.0 3 3 NaN 4 X Y Z 0 1.0 2 0.5 1 2.0 0 inf 2 3.0 3 1.0 3 NaN 4 NaN
I have a dataframe with two columns, one of which contains a NaN. I divide one of the columns by the ther to get a third column. The Nan is still there, and now there is another one.

Please provide an examle that demonstrates what you are talking about.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  adding a calculated column charles986 1 1,075 Jun-13-2024, 02:27 PM
Last Post: deanhystad
  Adding PD DataFrame column bsben 2 2,057 Mar-08-2024, 10:46 PM
Last Post: deanhystad
  How to calculated how many fail in each site(s) in csv files SamLiu 4 3,046 Sep-26-2022, 06:28 AM
Last Post: SamLiu
  Calculated DF column from dictionary value plantagenet 2 2,143 Sep-16-2022, 12:46 AM
Last Post: plantagenet
  Adding another condition for df column comparison Mark17 2 3,013 Sep-30-2021, 03:54 PM
Last Post: Mark17
  Adding a new column to a dataframe lokhtar 2 4,636 Jan-14-2021, 07:18 PM
Last Post: buran
  Adding markers to Folium map only adding last element. tantony 0 3,362 Oct-16-2019, 03:28 PM
Last Post: tantony
  Adding 2-column CSV together in base Python without using pandas LeegeeRicky 3 8,456 Sep-29-2019, 02:13 PM
Last Post: ichabod801
  How do I print a returned variable calculated in another function? RedSkeleton007 3 5,100 Jul-10-2018, 12:10 PM
Last Post: buran
  Sorting values calculated in python stumunro 4 5,864 Sep-13-2017, 06:09 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020