Python Forum
Extracting the correct data from a CSV file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extracting the correct data from a CSV file
#7
(Jun-02-2024, 08:07 PM)S2G Wrote: or "Print the moons in alphabetic order"
Just to give help with this task,it's the same start for the other task as you use DataFrame sat_df.
It's a typically dataset to be used with Pandas,you should mention what to use.
As regulars Python and Pandas are quite different.
import pandas as pd

file = 'satellites.csv'
sat_df = pd.read_csv(file)
# Sort the moons alphabetically
moons_sorted = sat_df.sort_values(by='name')
print(moons_sorted[['planet', 'name']])
Output:
planet name 17 Jupiter Adrastea 93 Saturn Aegaeon 107 Saturn Aegir 33 Jupiter Aitne 101 Saturn Albiorix .. ... ... 133 Uranus Titania 151 Uranus Trinculo 158 Neptune Triton 132 Uranus Umbriel 94 Saturn Ymir [177 rows x 2 columns]
Pedroski55 likes this post
Reply


Messages In This Thread
RE: Extracting the correct data from a CSV file - by snippsat - Jun-03-2024, 04:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [SOLVED] Correct way to convert file from cp-1252 to utf-8? Winfried 8 1,757 Feb-29-2024, 12:30 AM
Last Post: Winfried
  Extracting specific file from an archive tester_V 4 724 Jan-29-2024, 06:41 PM
Last Post: tester_V
  Extracting Data into Columns using pdfplumber arvin 17 6,438 Dec-17-2022, 11:59 AM
Last Post: arvin
  Extracting Specific Lines from text file based on content. jokerfmj 8 3,364 Mar-28-2022, 03:38 PM
Last Post: snippsat
  Extracting Data from tables DataExtrator 0 1,229 Nov-02-2021, 12:24 PM
Last Post: DataExtrator
  extracting data ajitnayak1987 1 1,655 Jul-29-2021, 06:13 AM
Last Post: bowlofred
  Extracting and printing data ajitnayak1987 0 1,486 Jul-28-2021, 09:30 AM
Last Post: ajitnayak1987
  Extracting unique pairs from a data set based on another value rybina 2 2,448 Feb-12-2021, 08:36 AM
Last Post: rybina
Thumbs Down extracting data/strings from Word doc mikkelibsen 1 2,039 Feb-10-2021, 11:06 AM
Last Post: Larz60+
  Extracting data without showing dtype, name etc. tgottsc1 3 4,946 Jan-10-2021, 02:15 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020