[Python] Displays the value of an empty cell as nan when recalling the value in the parsed excel sheet

Asked 1 weeks ago, Updated 1 weeks ago, 3 views

When parsing Excel files and storing them in variables

If specific cell empty

outputs at the output. that nan

I'm trying to empty my teeth again, but I don't know what to do

Even if you use isnan, you'll get an error

I'd appreciate it if you could tell me how to solve it

import panda as pd
import json
from collections import OrderedDict

df = pd.read_excel('Apple data.xlsx')

name = str(df.iloc[0,0])

prop02 = df.iloc[0,2]
prop03 = df.iloc[0,3]
prop04 = df.iloc[0,4]

'''
file_data = OrderedDict();

file_data["description"] = ""
file_data["external_url"] = ""
file_data["image"] = ""
file_data["name"] = name
file_data["attributes"] = ({'trait_type': 'Property01', 'value': df.iloc[0,1]},
                           {'trait_type': 'Property02', 'value': prop02},
                           {'trait_type': 'Property03', 'value': prop03},
                           {'trait_type': 'Property04', 'value': prop04})

with open(name +'.json','w',encoding="utf-8") as make_file:
    json.dump(file_data,make_file,ensure_ascii=False,indent="\t")
'''

python pandas

2022-09-19 23:32

1 Answers

Nan means not a number. If you want to enter the blank string when nan, it would be good to use the method below.

df = pd.read_excel('Apple data.xlsx', na_filter=False)


2022-09-19 23:32

If you have any answers or tips


© 2022 pinfo. All rights reserved.