what does data[:,0] or data[:,1] mean in pandas [duplicate] - pandas

This question already has answers here:
Extracting specific columns in numpy array
(10 answers)
Closed 2 years ago.
I am new to pandas and I saw some pandas code which says
plt.scatter(data[:,0],data[:,1])
I want to know what does data[:,0] and data[:,1] means?

Thas mean:
data[:,0] - > All the first column of the dataset
data[:,1] -> All the second colum of the dataset

Related

How do create lists of items for every unique ID in a Pandas DataFrame? [duplicate]

This question already has answers here:
How to get unique values from multiple columns in a pandas groupby
(3 answers)
Python pandas unique value ignoring NaN
(4 answers)
Closed 1 year ago.
Imagine I have a table that looks like this.
original table
How do I convert it into this?
converted table
Attached sample data. Thanks.

how do I split 1 str column into 2 columns in a pandas dataframe [duplicate]

This question already has answers here:
How to split a dataframe string column into two columns?
(11 answers)
Closed 2 years ago.
enter image description here
df['business location'] #column i want to split into 2 columns :
df['longitude'] #and
df['latitude']
df[['longitude','latitude']] = sf['Business Location'].str.split(',')
is giving me error:
ValueError: Must have equal len keys and value when setting with an iterable
how do I split?
This will work
df.assign(
longitude=lambda x: x['Business Location'].str.split(',').str[0],
latitude=lambda x: x['Business Location'].str.split(',').str[1])

How to convert ndarray to pandas DataFrame [duplicate]

This question already has answers here:
Convert two numpy array to dataframe
(3 answers)
Closed 3 years ago.
I have ndarray data with the shape of (231,31). now I want to convert this ndarray to pandas DataFrame with 31 columns. I am using this code:
for i in range (1,32):
dataset = pd.DataFrame({'Column{}'.format(i):data[:,i-1]})
but this code just creates the last column, it means with 231 indexes and just 1 column, but I need 31 columns. is there any way to fix this problem and why it happens?
Every time you are creating a new dataframe, that is why only the last column remains.
You need to create the dataframe with pd.DataFrame(data).

unable to convert groupby dataset to json in pandas [duplicate]

This question already has answers here:
How to reset index in a pandas dataframe? [duplicate]
(3 answers)
Closed 4 years ago.
I have group by data set but I'm unable to convert it to json. It throws out json with a bad format. TO_excel works fine.
Country Sub amount
3 source4
UK 1 source3
1 source1
US 2 source2
How can I export groupby dataset to_json?
There is problem you have MultiIndex in DataFrame, so need reset_index:
j = df.reset_index().to_json()
print (j)
{"Country":{"0":"UK","1":"UK","2":"US"},
"Sub":{"0":1,"1":1,"2":2},
"amount":{"0":"source3","1":"source1","2":"source2"}}

pandas dataframe to list(just care about data) [duplicate]

This question already has answers here:
Pandas DataFrame to List of Lists
(14 answers)
Closed 5 years ago.
I have a dataframe like this:
how can i get the list like:
[[2017-08-01,1.18263,1.18266,1.18109,1.18113],
......,
[2017-08-18,1.18263,1.18266,1.18109,1.18113]]
DataFrame.values returns the data as a numpy array, from there you can go to a list by adding tolist()