Last answered:

27 Feb 2023

Posted on:

03 Nov 2022

2

location_data becomes DataFrame type

After I import the csv file location.csv downloaded with Pandas read_csv method, it returns a DataFrame other than Series like the video showed. Therefore when I try to call .unique method, it threw an error saying this method does not work for DataFrame.

3 answers ( 0 marked as helpful)
Instructor
Posted on:

10 Nov 2022

1

Hi June!
Thanks for reaching out!

Could you please support your question with a screenshot containing the entire code you’ve executed? This can help us assist you better. Thank you.

Looking forward to your answer.
Best,
Tsvetelin

Posted on:

09 Jan 2023

1

PFA screenshot, Even when I am getting it as DataFrame instead of Series

image.png

Super learner
This user is a Super Learner. To become a Super Learner, you need to reach Level 8.
Posted on:

27 Feb 2023

1

So it looks like what is happening is when you remove the "squeeze = True" to get around the warning, it turns the imported file from a Series to a dataframe. Here is the correct syntax to get around the warning and maintain the imported file as a Series.


# squeeze is being depreciated; if you remove squeeze, it will turn into a data frame (and not a Series)
# Which will cause more issues in the next cells
# data = pd.read_csv('Location.csv', squeeze = True)


# This does not work either, it turns into a dataframe
# data = pd.read_csv('Location.csv')
# data.squeeze("columns")


# Correct syntax is:
data = pd.read_csv('Location.csv').squeeze("columns")

 

# Store a copy of this object’s indices and data.
location_data = data.copy()

 

# Display the first five rows
location_data.head()


Submit an answer