How to create an empty series using pandas?
import pandas as pd
series1 = pd.Series()
print(series1)
Here pd is an object of pandas package.\
series1 is a name of the empty series which we have created.
print(series1) is use to print the empty series
How to create series using a list data?
import pandas as pd
series1 = pd.Series([11,22,33,44,55])
print(series1)
here [11,22,33,44,55] is a list of python which is sending data to series1
How to create a series using range() function?
import pandas as pd
series1 = pd.Series(range(5))
print(series1)
Here range(5) function is use to feed the data in series. range function will feed the data as 0,1,2,3,4 in the series.
range(5) function will put the data from 0 to n-1 data. that means if 5 is written it will print 1 to 4 or if 7 is written it will print 0 to 6.
How to print the pandas series with default index and then rename the index to some names?
import pandas as pd
series1= pd.Series([11,22,33,44,55])
print(series1)
in this output the index will be printed as 0,1,2,3,4
series1.index = ["ONE","TWO","THREE","FOUR","FIVE"]
print(series1)
in this output index will be printed as "ONE","TWO","THREE","FOUR","FIVE"
How float values are handled in series pandas?
import pandas as pd
series1=pd.Series([11,22,33,44.44,55])
print(series1)
The output will be in float values. It will convert all the int values in float values, as this list has ONE element i.e 44.44 as float.
How to create a series with index values?
import pandas as pd
series1 = pd.Series([11,22,33,44,55],index=[101,102,103,104,105])
print(series1)
No comments:
Post a Comment