Example
1. Dataframe
dataframe → series
# dataframe
series_col1 = pd.series
print(series_col1)
print(type(series_col1))
dataframe → array
array = df.values
print(array)
print(type(array))
dataframe → list
lists = df.values.tolist()
print(lists)
print(type(lists))
dataframe → dictionay
dictionary = df.to_dict()
print(dictionary)
print(type(dictionary))
Series
Series → dataframe
df_col1 = pd.DataFrame(series_col1)
print(df_col1)
print(type(df_col1))
Series → array
array_col = np.array(series_col1)
print(array_col)
print(type(array_col))
Series → list
list_col = list(series_col1)
print(list_col)
print(type(list_col))
Series → dictionary
dict_col = series_col1.to_dict()
print(dict_col)
print(type(dict_col))
List
list → dataframe
list_df = pd.DataFrame(lists)
print(list_df)
print(type(list_df))
List → Series
list_series = pd.Series(lists)
print(list_series)
print(type(list_series))
List → Array
list_array = np.array(lists)
print(list_array)
print(type(list_array))
List → Dictionary
- 一个list
list1 = ['hello', 2, 'world', 11]
list_dict = dict(zip(list1[0::2], list1[1::2]))
print(list_dict)
print(type(list_dict))
- 两个list
keys = ['col1', 'col2']
values = [1, 2]
lists_dict = dict(zip(keys, values))
print(lists_dict)
print(type(lists_dict))
参考:在python 中如何将 list 转化成 字典(dictionary)
Dictionary
Dictionary → Dataframe
dic = pd.DataFrame(dictionary)
print(dic)
print(type(dic))
Dictionary → Series
series = pd.Series(dictionary)
print(series)
print(type(series))
Dictionary → List
- List of keys
keys - dictionary.keys()
#keys = list(dictionary)
print(keys)
print(type(keys))
- List of values
values = dictionary.values()
print(values)
print(type(values))
Dictionary → Array
array = np.array(dictionary)
print(array)
print(type(array))
Array
Array → Dataframe
array_df = pd.DataFrame(array)
print(array_df)
print(type(array_df))
Array → Series
# series只能是一维的
array_series = pd.Series(array[1])
print(array_series)
print(type(array_series))
Array → List
array_list = list(array)
print(array_list)
print(type(array_list))