Complete the code to create a pandas Series with string data type.
import pandas as pd s = pd.Series(['apple', 'banana', 'cherry'], dtype=[1]) print(s.dtype)
Using dtype="string" creates a Series with pandas string type.
Complete the code to convert a pandas Series to string type.
import pandas as pd s = pd.Series([1, 2, 3]) s = s.[1]() print(s.dtype)
Use astype(str) to convert a Series to string type.
Fix the error in the code to check if the Series has string dtype.
import pandas as pd s = pd.Series(['a', 'b', 'c'], dtype='string') if s.dtype == [1]: print("Series is string type")
Use pd.StringDtype() to compare dtype for pandas string type.
Fill both blanks to create a DataFrame column with string type and check its dtype.
import pandas as pd df = pd.DataFrame({'name': ['Tom', 'Jane', 'Alice']}) df['name'] = df['name'].[1]([2]) print(df['name'].dtype)
Use astype("string") to convert the column to string dtype.
Fill all three blanks to create a Series with string dtype, convert it to object dtype, and print both dtypes.
import pandas as pd s = pd.Series(['x', 'y', 'z'], dtype=[1]) s_obj = s.[2]([3]) print(s.dtype, s_obj.dtype)
Create a string dtype Series with "string", convert to object dtype with astype("object").
