'Getting Nan values instead of the float output assigned to populate the field

*lightning_files *is a list of file paths.

for file in lightning_files:
  sset = pd.read_csv(file)
  name_file = Path(file).stem  #Gives me the name of file
  split_name = name_file.split('_')
  sum_weight = sset['Total Weight'].sum()  #'Total Weight': A column in the file
  hail_master.loc[hail_master['Key'] == split_name[1], "Sum_of_weights"] = sum_weight

In the end the new column "Sum_of_weights" has all Nan values. Also, I have checked but sum_weight values are never empty. They are though small numbers like in the range of 0.00001. Not sure if that makes any difference.

Can someone help debugg this?

I tried to see if the Total_weights column was empty or not but no it has values for all the files. Rest I think my logic was on point but still unsure about the problem.



Solution 1:[1]

Would need an example of the filename that you're trying to parse, most likely that the 'Key' column in hail_master isn't able to find a match to the second element in name_file

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 harrrshitt