dataframe to list
df.values.tolist()
dataframe to list
df.values.tolist()
how to make a pandas dataframe from lists
# Short answer:
# The simplest approach is to make a dictionary from the lists and then
# to convert the dictionary to a Pandas dataframe.
# Example usage:
import pandas as pd
# Lists you want to convert to a Pandas dataframe
months = ['Jan','Apr','Mar','June']
days = [31, 30, 31, 30]
# Make dictionary, keys will become dataframe column names
intermediate_dictionary = {'Month':months, 'Day':days}
# Convert dictionary to Pandas dataframe
pandas_dataframe = pd.DataFrame(intermediate_dictionary)
print(pandas_dataframe)
Month Day
0 Jan 31
1 Apr 30
2 Mar 31
3 June 30
how to create a dataframe from two lists in python
# Python 3 to get list of tuples from two lists
data_tuples = list(zip(Month,Days))
data_tuples
[('Jan', 31), ('Apr', 30), ('Mar', 31), ('June', 30)]
>pd.DataFrame(data_tuples, columns=['Month','Day'])
Month Day
0 Jan 31
1 Apr 30
2 Mar 31
3 June 30
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us