0

please see attached photo here's the image

I only need to import a specific column with conditions(such as specific data found in that column). And also, I only need to remove unnecessary columns. dropping them takes too much code. What specific code or syntax is applicable?

1 Answers1

0

How to get a column from pandas dataframe is answered in Read specific columns from a csv file with csv module?

To quote:

Pandas is spectacular for dealing with csv files, and the following code would be all you need to read a csv and save an entire column into a variable:

import pandas as pd
df = pd.read_csv(csv_file)
saved_column = df.column_name #you can also use df['column_name']

So in your case, you just save the the filtered data frame in a new variable.
This means you do newdf = data.loc[...... and then use the code snippet from above to extract the column you desire, for example newdf.continent

Welsy
  • 77
  • 11
  • somehow, im getting errors in 'saved_column'. can i save multiple columns? I used this code, but it happened to have error. what's wrong? when i use only one column and snippet, it works. here's what i have done saved_column = df['location', 'location' ,'date', 'total_cases', 'new_cases', 'total_deaths', 'new_deaths'] – Persnickety Nov 30 '21 at 03:47