How to Convert CSV to JSON in Python

Поделиться
HTML-код
  • Опубликовано: 4 янв 2025

Комментарии •

  • @saucecode5544
    @saucecode5544 2 года назад +1

    Thanks for the tutorial. Even after 2 years, this video was useful. Now I can use this to create api's

    • @python-programming
      @python-programming  2 года назад

      No problem! You can also use pandas. I have been thinking of doing that video too

  • @RyanC119
    @RyanC119 2 года назад +1

    Incredibly helpful and clearly explained. Thank you!

  • @defaultname1700
    @defaultname1700 2 года назад +1

    This video solved a myriad of problems, thanks

  • @mankind770
    @mankind770 3 года назад +2

    Awesome !!! Much thanks mate

  • @henriquebalzani1563
    @henriquebalzani1563 3 года назад +2

    OMG!! thank you... Just what I needed it

  • @JoeCole_social
    @JoeCole_social 3 года назад +2

    This saved me so much time thank you so much! please consider some sort of tip jar so I can contribute and support your efforts.

    • @python-programming
      @python-programming  3 года назад +1

      I'm very pleased it helped you! Right now, I just use Paypal's donation: www.paypal.com/donate/?cmd=_donations&business=AZ73QW52SUX8N¤cy_code=USD&source=url Thanks for the contribution!

  • @andrejsopsis6109
    @andrejsopsis6109 2 года назад +1

    Thnak you , at most about last minute without "names"

  • @mathketeer
    @mathketeer 2 года назад

    Very clear, very helpful, very simple, very GREAT.

  • @KiranKumar-zb6ly
    @KiranKumar-zb6ly 3 года назад +1

    Sir what we want to do if we want to convert only particular columns of csv file into json. plz reply quickly

  • @andrewburnley917
    @andrewburnley917 2 года назад

    This is awesome!

  • @aravindjeffhardy
    @aravindjeffhardy 3 года назад

    Very Nice, It helped me a lot. Thank you so much

  • @LimpiaPeceras
    @LimpiaPeceras 3 года назад +2

    Hi! Thanks for the video. I have one error when I try to read the json "'utf-8' codec can't decode byte 0xff in position 0: invalid start byte". Could you help me? Thanks

    • @python-programming
      @python-programming  3 года назад

      Hi! It is hard to tell without seeing your data, but it sounds like an encoding error. You will need to figure out what encosing your data is using and load it as that rather than utf-8 or pass an error arugment to skip characters that return an error.

  • @manmeetkaur4472
    @manmeetkaur4472 3 года назад

    Hi, its a great code but I have a question here, If I want the output as {Bob:28, Fred:32, Jim:35}.... Don't want the header as keys.......just want both the columns as keys and values in one dictionary. How can I do that?

  • @olatundeibrahim8355
    @olatundeibrahim8355 2 года назад +1

    Hello. This method is not working for csv file with larger number of rows and columns. Can someone please assist?

    • @python-programming
      @python-programming  2 года назад

      If you are familiar with pandas, you can load it up in pandas with read csv and then save it with to json. Remmeber to set index to False

  • @mankind770
    @mankind770 3 года назад

    Is this method okay for when working with large set of data. I mean getting the row number might not be always easy

  • @xXCLAVERYXx
    @xXCLAVERYXx 3 года назад

    Hi Thanks for this but how could I limit the size as Im using a large dataset and only really want about 1000 records.

  • @Shubhankar.Banerjee
    @Shubhankar.Banerjee 3 года назад +1

    Text size is very small. Difficult to read text on mobile screen.

  • @mehakrani3614
    @mehakrani3614 2 года назад

    can you convert csv to arff data format ?

  • @KhalilYasser
    @KhalilYasser 3 года назад +2

    Awesome. Thank you very much.
    In the json output I noticed that the numbers are like strings. How can I make numbers as integers (without quotations in the json output)?

    • @python-programming
      @python-programming  3 года назад +1

      Good question. Before outputting to JSON, insure that your integer or float is not a string by converting it with int("STRING GOES HERE") or float()

    • @KhalilYasser
      @KhalilYasser 3 года назад +1

      @@python-programming Can you guide me on what line should I modify? Do you mean in that part `int(row[1]`

    • @python-programming
      @python-programming  3 года назад +1

      @@KhalilYasser Of course. So line 10 I would change row[1] to int(row[1]) --- I haven't tested this, but that will convert any instance of a string to an integer

    • @KhalilYasser
      @KhalilYasser 3 года назад +1

      @@python-programming Amazing. I have tested and it worked well. Thank you very much.

    • @python-programming
      @python-programming  3 года назад +1

      @@KhalilYasser Yay! Excellent. Glad I could help. No worries at all.

  • @SaysAnX
    @SaysAnX Год назад

    y con un csv que se tiene en drive?

  • @kyleb3316
    @kyleb3316 3 года назад +1

    Great tutorial, do you have another where you go into more nested dictionaries?

    • @python-programming
      @python-programming  3 года назад

      Thanks! I do not at the moment. The process will work the same regardless of the data structure. It is just a matter of accessing the nested data via Python.

  • @amitdighe1
    @amitdighe1 3 года назад +1

    Thanks for your video, the only problem I am facing here is after the conversion, the order of the fields is not maintained in JSON file as of CSV. Do you have any workaround on that?

  • @SkyOcean-lg7lt
    @SkyOcean-lg7lt Год назад

    What a God you are!

  • @ola419rrie
    @ola419rrie 3 года назад

    Thanks for this tutorial, what if our CSV file had more rows and we wanted to append some of the rows to form nested dictionaries.

  • @ironfrogclark
    @ironfrogclark 3 года назад +1

    what IDE are you using?

  • @AndyArismendi
    @AndyArismendi 2 года назад

    I know this is a python tutorial but for what it's worth, the equivalent in powershell: @{Names = (Import-Csv names.csv)} | ConvertTo-Json

  • @14silber
    @14silber 3 года назад

    Thanks for your video

  • @honaidaattaher4549
    @honaidaattaher4549 2 года назад

    thank you so much

  • @kaushikrana5680
    @kaushikrana5680 2 года назад +1

    Hey , how to make multiple keys ?? Like :
    { "AB" :
    { "..." :
    { "..." :
    {"..." , "....." }
    }
    }
    }

    • @python-programming
      @python-programming  2 года назад

      Csv files are not good at storing this type of data structure. You are better off leaving it as a JSON file.