w3resource

Pandas Data Series: Add some data to an existing Series

Pandas: Data Series Exercise-12 with Solution

Write a Pandas program to add some data to an existing Series.

Sample Solution :

Python Code :

import pandas as pd
s = pd.Series(['100', '200', 'python', '300.12', '400'])
print("Original Data Series:")
print(s)
print("\nData Series after adding some data:")
new_s = s.append(pd.Series(['500', 'php']))
print(new_s)

Sample Output:

Original Data Series:
0       100
1       200
2    python
3    300.12
4       400
dtype: object

Data Series after adding some data:
0       100
1       200
2    python
3    300.12
4       400
0       500
1       php
dtype: object                     

Python Code Editor:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program to convert Series of lists to one Series.
Next: Write a Pandas program to create a subset of a given series based on value and condition.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Returns a list with n elements removed from the beginning

Example:

def tips_take(itr, n = 1):
  return itr[:n]
print(tips_take([1, 2, 3], 5))
print(tips_take([1, 2, 3], 0))

Output:

[1, 2, 3]
[]