Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas from series to dataframe

#To convert a series to a dataframe simply apply the to_frame() method
#to the series
s.to_frame() 
Comment

pandas.core.series.series to dataframe

>>> s = pd.Series(["a", "b", "c"],
...               name="vals")
>>> s.to_frame()
  vals
0    a
1    b
2    c
Comment

pd df to series

import pandas as pd

data = {'First_Name': ['Jeff','Tina','Ben','Maria','Rob']}
df = pd.DataFrame(data, columns = ['First_Name'])

print(df)
#	First_Name
#0       Jeff
#1       Tina
#2        Ben
#3      Maria
#4        Rob

print(type(df))
# <class 'pandas.core.frame.DataFrame'>

df = df.squeeze() # <- Converts to a pandas series
print(df)
#0     Jeff
#1     Tina
#2      Ben
#3    Maria
#4      Rob
#Name: First_Name, dtype: object

print(type(df))
# <class 'pandas.core.series.Series'>
Comment

series.Series to dataframe

df = pd.DataFrame([s])
print (df)
         product_id_y  count
6159402       1159730      1
Comment

pandas dataframe to series

df.squeeze() # converts to series
# OR
# When loading a file
pd.read_csv("df.csv", index_col="col1", squeeze=True) 
Comment

pandas dataframe to series

series = df.squeeze() # Convert df to series
Comment

series to dataframe

pd.DataFrame({'email':sf.index, 'list':sf.values})
Comment

convert series to dataframe pandas

In [119]:

common = df1.merge(df2,on=['col1','col2'])
print(common)
df1[(~df1.col1.isin(common.col1))&(~df1.col2.isin(common.col2))]
   col1  col2
0     1    10
1     2    11
2     3    12
Out[119]:
   col1  col2
3     4    13
4     5    14
Comment

PREVIOUS NEXT
Code Example
Python :: python - show repeted values in a column 
Python :: initialize array of natural numbers python 
Python :: how to use prettytable with python 
Python :: Multiple Box Plot using Seaborn 
Python :: extract text regex python 
Python :: pandas convert date to quarter 
Python :: how to write your first python program 
Python :: setting a condition for perfect square in python 
Python :: python filter list of dictionaries by value 
Python :: isinstance float or int 
Python :: python find first duplicate numbers 
Python :: export a dataframe to excel pandas 
Python :: how to click on button using python 
Python :: create 2d list dictionary 
Python :: string to datetime python 
Python :: Print the norm of a vector and a matrix using numpy. 
Python :: pandas shift columns down until value 
Python :: list of files to zip python 
Python :: Get the Type 
Python :: pandas row where value in list 
Python :: screen size python 
Python :: cast tensor type pytorch 
Python :: horizontal bar plot python 
Python :: tofixed in python 
Python :: how to create random tensor with tensorflow 
Python :: error urllib request no attribute 
Python :: python requests port 
Python :: python remove form list 
Python :: add dir to path python 
Python :: python transpose list of lists 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =