MY BABY!!! sandy!!! frolicking in the sun!!!!
/////////////// ANSWERS TO SOME QUESTIONS IN PYTHON: /////////
1. WHAT IS A SERIES AND HOW TO CREATE A SERIES
Series is a one-dimensional labeled array capable of holding
data of any type (integer, string, float, python objects, etc.)
Heres is the syntax :
>>> pd.Series([1, 2, "Mary", "George"], name="name of series",
index, dtype, copy])
2. WHAT IS A LIST IN PYTHON ###############################
A list is a data structure in Python that is a mutable, or
changeable, ordered sequence of elements. Each element or
value that is inside of a list is called an item. Just as
strings are defined as characters between quotes, lists are
defined by having values between square brackets [ ]
5. WHAT IS A DICTIONARY IN PYTHON AND WHAT IS THE SYNTAX
A dictionary is a collection which is ordered*, changeable
and does not allow duplicates. As of Python version 3.7,
dictionaries are ordered.
In Python 3.6 and earlier, dictionaries are unordered.
Dictionaries are written with curly brackets, and have keys
and values: Example. Create and print a dictionary:
Basic syntax is:
>>> dict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
*** you can also create a key with multiple values (like a
column with multiple cells...)
dict = {
"brand": ["Ford", "Chrysler", "Toyota"],
"model": ["Mustang", "Van", "Camry"],
"year": [1964, 1971, 1998],
}
6. HOW TO CREATE A SERIES FROM A DICTIONARY?
With PANDAS library you can do this:
df = pd.Series(dict)
7. HOW TO CREATE A DICTIONARY FROM A SERIES?
df = pd.Series.to_dict(dict)
8. PARAMETERS AVAILABLE IN PANDA'S READ_EXCEL ARE?
pandas.read_excel(
io,
sheet_name=0,
header=0,
names=None,
index_col=None,
usecols=None,
squeeze=False,
dtype=None,
engine=None,
converters=None,
true_values=None,
false_values=None,
skiprows=None,
nrows=None,
na_values=None,
keep_default_na=True,
na_filter=True,
verbose=False,
parse_dates=False,
date_parser=None,
thousands=None,
comment=None,
skipfooter=0,
convert_float=True,
mangle_dupe_cols=True,
storage_options=None
)
9. Extracting multiple rows with same index
In this example, Team name is made as the index column and one team
name is passed to .loc method to check if all values with same team
name have been returned or not.
# importing pandas package
import pandas as pd
# making data frame from csv file
data = pd.read_csv("nba.csv", index_col ="Team")
# retrieving rows by loc method
rows = data.loc["Utah Jazz"]
# checking data type of rows
print(type(rows))
# display
rows
10. PANDAS CSV READ METHOD
pandas.read_csv(
filepath_or_buffer,
sep=<object object>,
delimiter=None,
header='infer',
names=None,
index_col=None,
usecols=None,
squeeze=False,
prefix=None,
mangle_dupe_cols=True,
dtype=None,
engine=None,
converters=None,
true_values=None,
false_values=None,
skipinitialspace=False,
skiprows=None,
skipfooter=0,
nrows=None,
na_values=None,
keep_default_na=True,
na_filter=True,
verbose=False,
skip_blank_lines=True,
parse_dates=False,
infer_datetime_format=False,
keep_date_col=False,
date_parser=None,
dayfirst=False,
cache_dates=True,
iterator=False,
chunksize=None,
compression='infer',
thousands=None, decimal='.',
lineterminator=None,
quotechar='"',
quoting=0,
doublequote=True,
escapechar=None,
comment=None,
encoding=None,
dialect=None,
error_bad_lines=True,
warn_bad_lines=True,
delim_whitespace=False,
low_memory=True,
memory_map=False,
float_precision=None,
storage_options=None
)
Comments
Post a Comment