0
$\begingroup$

I have try to drop a nan value like so

import pandas
data = pandas.read_json("data.json")
lat = data["Latitude"]
lng = data["Longitude"]
shop = data["Store - Business Name"]
df2 = lat.dropna(axis=0, how='any')
df1 = pandas.to_numeric(df2, errors='coerce')

print(df1)

what am i missing, because i still get nan value in my panda series.

$\endgroup$
  • $\begingroup$ Pandas can be quite tricky to start with. What you can do to drop rows with missing Latitude values is simply df = df.dropna(axis= 0, subset= ['Latitude']). In this case, the subset parameter is the list of columns that are included in the procedure. $\endgroup$ – Vlad_Z Aug 1 '19 at 13:29
  • $\begingroup$ Can you accept the question since it works? $\endgroup$ – Ilker Kurtulus Nov 27 '19 at 8:15
3
$\begingroup$

lat is a series in your data, if you have even only one nan value in your series ,lat, then you will loose all of your series. Another problem might be in the lat column values might not be suitable for converting to pd.to_numeric such as "1,2" (not "1.2"), "a", "nan" etc. Then you will loose your series again. Therefore:

Check: len(lat.dropna()) == len(lat) if it is True then check:

len(df2[df2.str.contains(",")]) > 0

I hope it works!

| improve this answer | |
$\endgroup$
0
$\begingroup$

df2 = lat.dropna(axis=0, how='any') it is deleting entire row which is having any of the nan values instead use df2 = lat.dropna(axis=0, how='all') if want to drop all the rows which are having nan values.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.