Is there a way to remove nan from a dictionary filled with data?

后端 未结 4 1050
悲哀的现实
悲哀的现实 2021-01-12 06:51

I have a dictionary that is filled with data from two files I imported, but some of the data comes out as nan. How do I remove the pieces of data with nan?

My code i

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-12 07:44

    Know old, but here is what worked for me and simple - remove NaNs on reading of the CSV upfront:

    orangebook = pd.read_csv('C:\Users\WEGWEIS_JAKE\Desktop\Work Programs\Code Files\products2.txt',sep='~', parse_dates=['Approval_Date']).dropna()
    

    I also like to convert to dictionary at the same time:

    orangebook = pd.read_csv('C:\Users\WEGWEIS_JAKE\Desktop\Work Programs\Code Files\products2.txt',sep='~', parse_dates=['Approval_Date']).dropna().to_dict()
    

提交回复
热议问题